【发布时间】:2019-10-08 23:22:25
【问题描述】:
我正在使用来自 nestjs (https://github.com/nestjs/nest/tree/master/sample/03-microservices) 的微服务混合示例来熟悉基础知识。它目前使用位于 src 文件夹 (src/math) 内的微服务。我想将微服务移动到微服务文件夹 (microservices/math/...) 下的根文件夹中,以便可以在此结构中构建其他微服务。
当我使用 "start:prod": "node dist/main.js" 运行它时,如果我在 app.module.ts 中导入的 math.module 是示例中的那个,在 './math/ math.module' 它工作正常。如果我将数学文件夹内容复制到根目录的微服务文件夹中,并从“../microservices/math.module”中引用math.module,那么我所拥有的dist结构是错误的:
- 分布
- 微服务
- 源
- 常见
- 数学
- 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"]
}
【问题讨论】:
-
你是在用 tsc 命令编译你的项目吗?这可能是您的 tsconfig.json 文件中的配置问题...粘贴它。
-
@KevinMansel 我用 tsconfigs 编辑了答案。另外这个例子是为了举例说明我在另一个项目中遇到的问题,这个问题更详细地分享(nestjs with ssr、混合微服务设置、角度等)。
-
@KevinMansel 你有什么想法吗?
标签: node.js typescript nestjs tsc tsconfig