我在打字稿中使用路径它可以与tsc-watch一起正常工作,但是当我生成js构建文件并使用node dist / main.js运行它时,我会得到
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module '@config/typeorm.config'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/home/kronos/nestjs-backend/dist/app.module.js:11:26)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
我的tsconfig.json文件如下:
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es2017",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./src",
"paths": {
"@utils/*": [
"./utils/*"
],
"@dto/*": [
"./dto/*"
],
"@middlewares/*": [
"./middlewares/*"
],
"@modules/*": [
"./modules/*"
],
"@config/*": [
"./config/*"
]
},
"incremental": true
},
"exclude": [
"node_modules",
"dist"
]
}