当服务器从外部文件夹导入模块时,在dist /文件夹中构建错误

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

我正在使用nestjs(https://github.com/nestjs/nest/tree/master/sample/03-microservices)中的微服务混合示例,以熟悉基础知识。当前,它使用位于src文件夹(src / math)中的微服务。我想将微服务移到微服务文件夹(microservices / math / ...)下的根文件夹中,以便可以在此结构中构建其他微服务。

当我使用app.module.ts导入的math.module是一个示例时,例如'./math/math,如果我使用“ start:prod”:“ node dist / main.js”运行它, .module”,效果很好。如果我将数学文件夹内容复制到根目录中的microservices文件夹中,并且从'../microservices/math.module'引用math.module,则dist结构在我有的地方是错误的:

  • dist
    • 微服务
    • src
      • 普通
      • 数学
      • app.module.d.ts
      • main.d.ts

当然,在这种情况下,它将尝试在“ dist”内运行main.js,但不再存在,因为它会自动放入src而不是dist文件夹的根中。

这纯粹是我需要调整的打字稿配置吗?

tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "noImplicitAny": false,
    "removeComments": true,
    "noLib": false,
    "allowSyntheticDefaultImports": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es6",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./"
  },
  "exclude": ["node_modules"]
}

tsconfig.build.json

{
  "extends": "./tsconfig.json",
  "include": ["src/**/*"],
  "exclude": ["node_modules", "**/*.spec.ts"]
}
node.js typescript nestjs tsc tsconfig
1个回答
0
投票

这里的问题是,当您从文件夹中import本地代码时,这不是用于构建的include中的tsconfig.json d。在这种情况下,打字稿将使用代码进入最不深度文件夹的父文件夹,并构建该文件夹树的结构,因为构建的文件之间应具有相同的相对路径。

© www.soinside.com 2019 - 2024. All rights reserved.