I am using typescript alias paths on my express app. After build the alias path not replace it with relative path and when I run my code with:
"start": "node ./dist/src/index.js"
It’s showing the following error:
$ node ./dist/src/index.js
node:internal/modules/cjs/loader:1075
throw err;
^
Error: Cannot find module '@/routes/index'
My tsconfig file :
{
"compileOnSave": true,
"compilerOptions": {
"strict": true, // used to strictly check the types of variables
"target": "es2016",
"lib": ["ES6"],
"types": ["node", "express"],
"module": "commonjs",
"outDir": "./dist",
"rootDir": ".",
"sourceMap": true,
"moduleResolution": "node",
"noImplicitAny": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"noUnusedLocals": false, // used to check if any variable is not used
"noUnusedParameters": false, // used to check if any parameter is not used
"importHelpers": true,
"baseUrl": "src",
"paths": {
"@/*": ["*"],
"@config": ["config"],
"@controllers/*": ["controllers/*"],
"@middlewares/*": ["middlewares/*"],
"@routes/*": ["routes/*"],
"@utils/*": ["utils/*"],
"@services/*": ["services/*"]
},
},
"include": ["src/**/*.ts", "src/**/*.json", ".env"],
"exclude": ["node_modules", "build"],
"ts-node": {
"require": ["tsconfig-paths/register"]
}
}