While building the "users" application, nestjs merges "gateway" application in dist folder of "users" dir instead of just compiling "src" folder of "users" dir
dir structure:
RootDir
---gateway //External nest app
---microservices
------users //Nest app to build
After calling 'yarn build' in users dir I can find dist folder with the following structure:
dist
---gateway
---microservices
------users
I use standard compile options built by nest-cli:
#nest-cli.json
{
"collection": "#nestjs/schematics",
"sourceRoot": "src",
"watchAssets": true
}
#tsconfig.build.json
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
}
#tsconfig
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "es2017",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": false,
"noImplicitAny": false,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false
}
}
Related
Works fine in my local environment but when i try to deploy my server getting
Error: Cannot find module 'react'
on /project/src/node_modules/next-auth/react/index.js
it seems like next-auth using React for some parts.
my ts config:
{
"compilerOptions": {
"target": "es2022",
"lib": ["ES2022"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "ES2022",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true
},
"exclude": ["node_modules"],
"ts-node": {
"esm": true,
"experimentalSpecifierResolution": "node"
}
}
my package.json:
I've used ts-node --esm for build command
I'm maintain a fork of a repo, during my last update I applied changes however now typescript will not recognize absolute pathing.
I've made no changes to my tsconfig.json:
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"alwaysStrict": true,
"baseUrl": "src",
"downlevelIteration": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"jsx": "react-jsx",
"lib": ["dom", "dom.iterable", "esnext"],
"module": "esnext",
"moduleResolution": "node",
"noEmit": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": false,
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"strictNullChecks": true,
"target": "es5",
"types": ["jest", "node"],
"useUnknownInCatchVariables": false
},
"exclude": ["node_modules", "cypress"],
"include": ["src/**/*"]
}
However now the compiler doesn't recognize paths that looks like so:
import { useIsDarkMode } from 'state/user/hooks'
Something went wrong with the node_modules, after I deleted them and called
yarn clean cache
yarn
Then everything started to work again
How do you setup paths with typescript to run with ts-node? And later compile paths to absolute paths when compiling?
I have following very minimal structure:
koki.ts:
export const calculate = (a: number, b: number) => {
return a + b;
};
index.ts:
import { calculate } from "#koki/koki";
const result = calculate(1, 2);
console.log(result);
tsconfig.json:
{
"ts-node": {
"transpileOnly": true,
"require": ["tsconfig-paths/register"]
},
"compilerOptions": {
"target": "es2017",
"module": "commonjs",
"lib": ["dom", "es6", "es2017", "esnext.asynciterable"],
"skipLibCheck": true,
"sourceMap": true,
"outDir": "./dist",
"moduleResolution": "node",
"removeComments": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"resolveJsonModule": true,
"baseUrl": ".",
"paths": {
"#/*": ["*"],
"#koki/*": ["koki/*"]
}
},
"exclude": ["node_modules"],
"include": ["./src/**/*.ts"]
}
I am getting:
ts-node src/index.ts
Error: Cannot find module '#koki/koki'
Require stack:
- /home/pwnage/Documents/github/test-node/src/index.ts
In my case, I added the -r option to ts-node scripts
package.json
"scripts": {
"start": "ts-node -r tsconfig-paths/register src/index.ts",
}
ts-node works well in these codes
import { env } from "#/config/env";
I'm working on a project that uses node.js with typescript. If I run TSC or a command to build the project, it works because I have the option "experimentalDecorators": true in my tsconfig.json.
But when I put it into my dev server using pm2 with the same configuration, doesn't work using the exosystem.config.json and without.
First, I have this tsconfig.json:
{
"compilerOptions": {
"target": "es2017",
"module": "commonjs",
"lib": ["dom", "es6", "es2017", "esnext.asynciterable"],
"skipLibCheck": true,
"sourceMap": true,
"outDir": "./dist",
"moduleResolution": "node",
"removeComments": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"noImplicitThis": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"resolveJsonModule": true,
"rootDir": "src",
"composite": true,
"declaration": true,
"noEmitOnError": false,
"preserveConstEnums": true,
},
"exclude": ["node_modules"],
"include": ["src"],
}
My project structure is:
index.ts
tsconfig.json
src/
ecosystem.config.js
My ecosystem.config.js is:
module.exports = {
apps : [{
name: "app",
script: './index.ts',
autorestart: true,
exec_mode: "fork",
watch: true,
env: {
NODE_ENV: 'development',
},
env_production: {
NODE_ENV: 'production',
},
}
],
};
And if I debug the pm2 logs I have this error:
Error
I solve this error with this ecosystem.config.js configuration:
module.exports = {
apps : [{
name: 'app',
script: './node_modules/.bin/ts-node',
args: '-P ./tsconfig.json ./index.ts',
watch: true,
restart_delay: 10000,
wait_ready: true
}],
};
I have aliases in my client app, and I 'm trying to do the same on the backend with typescript. I wrote:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"lib": ["es6"],
"allowJs": true,
"outDir": "build",
"rootDir": "src",
"strict": true,
"noImplicitAny": false,
"skipLibCheck": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"paths": {
"mails/*": ["src/mails/*"],
"models/*": ["src/models/*"],
"routers/*": ["src/routers/*"],
"routes/*": ["src/routes/*"],
"utils/*": ["src/utils/*"]
},
"exclude": ["node_modules"]
}
}
But then when importing a file such as: import authRouter from "routers/auth" , Typescript claims that:
Cannot find module 'routers/auth' or its corresponding type declarations.
How to allow aliases path in a node/express server?