我有一个 NestJS 应用程序,其
compilerOptions.paths
指定如下:
"paths": {
"@core/interceptors": [
"core/interceptors/index.ts"
]
}
然后我在控制器中像这样导入它:
import { ResponseValidationInterceptor } from '@core/interceptors';
IDE 中没有错误,但是当我尝试提供应用程序时,收到以下错误提示:
Error: Cannot find module '../../core/interceptors/index.ts'
当我检查
dist/
文件夹时,我可以在controller
文件中看到,导入拦截器的路径看起来是const interceptors_1 = require("../../core/interceptors/index.ts");
我尝试使用
module-alias
npm 包,通过在我的 addAlias('@core/interceptors', 'core/interceptors/index.js');
文件中的导入列表后指定 main.ts
,但它没有任何效果。
如何调整我的
tsconfing.json
或 tsconfig.build.json
来正确编译此路径?