我们正在为不同的服务运行几个 NestJS 应用程序。它们都共享一些通用代码,在我们的例子中是 ConfigModule 和 CacheModule。我想将它们分解并放入公司“通用”npm 包中,以最大程度地减少代码复制。
\n但我遇到了一个错误:
\n\n\nNest 无法导出不属于当前处理的模块 (ConfigModule) 的\n组件/模块。请验证每个\n导出的单元在此特定上下文中是否可用
\n
我有点不知道问题到底是什么。任何帮助深表感谢。
\n在app.ts服务 A 中:
import {\xc2\xa0ConfigModule } from \'@company/npm-common\';\n...\n@Module({\n imports: [ConfigModule, ...],\n})\nexport class AppModule {}\nRun Code Online (Sandbox Code Playgroud)\n现在@company/npm-common导入到 package.json 中file:../npm-common
npm-common/index.ts:
export * from \'./Config\';\nRun Code Online (Sandbox Code Playgroud)\nnpm-common/Config/index.ts
export { ConfigService } from \'./config.service\';\nexport { ConfigModule }\xc2\xa0from \'./config.module\';\nRun Code Online (Sandbox Code Playgroud)\nnpm-common/Config/config.service:
import { Global, Module } from \'@nestjs/common\';\nimport { ConfigService } from \'./config.service\';\n\n@Global()\n@Module({\n providers: [\n {\n provide: ConfigService,\n useValue: new ConfigService(),\n },\n ],\n exports: [ConfigService],\n})\nexport class ConfigModule {}\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
2071 次 |
| 最近记录: |