我正在尝试将我的 NestJS TS 应用程序迁移到 ESM。
这是我的 tsconfig.json
{
"compilerOptions": {
"module": "esnext",
"moduleResolution": "node",
"declaration": false,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"skipDefaultLibCheck": true,
"target": "es2021",
"outDir": "./dist",
"baseUrl": "./",
"incremental": true,
"esModuleInterop": true,
"strictNullChecks": true,
"noImplicitOverride": true,
"skipLibCheck": true,
"sourceMap": true,
"paths": {},
"resolveJsonModule": true
}
}
我的 package.json
{
"type": "module",
"engines": {
"node": "^16 || >=18"
},
"scripts": {
"start:dev": "nest start --watch",
},
"dependencies": {
"@nestjs/cli": "^9.3.0",
"@nestjs/common": "^9.3.10",
"@nestjs/core": "^9.3.10",
//...
},
"devDependencies": {
// ...
"typescript": "^4.9.5"
},
}
但是当我运行
npm run start:dev
时,我得到这个错误:Cannot find module '.../dist/src/app.module' imported from .../dist/src/main.js
.
我试过调整 tsconfig.json 但我从来没有设法找到一个有效的配置...
在
src/main.ts
中,我像这样导入AppModule:
import { AppModule } from './app.module';