NestJS 构建未正确编译指向 index.ts 的 tsconfig.paths

问题描述 投票:0回答:1

我有一个 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
来正确编译此路径?

typescript nestjs tsconfig tsc
1个回答
0
投票

路径应该是一个文件夹,而不是特定文件,请阅读此处的文档

这是我使用路径的示例:

 "paths": {
      "@model/*": ["src/model/*"]
    },
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.