作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们正在为不同的服务运行几个 NestJS 应用程序。它们都共享一些公共(public)代码,在我们的例子中是一个 ConfigModule 和一个 CacheModule。我想将它们分解并放入公司的“通用”npm 包中,以最大程度地减少代码复制。
不过我遇到了一个错误:
Nest cannot export a component/module that is not a part of thecurrently processed module (ConfigModule). Please verify whether eachexported unit is available in this particular context
我有点不知道问题到底是什么。非常感谢任何帮助。
在服务 A 的 app.ts
中:
import { ConfigModule } from '@company/npm-common';
...
@Module({
imports: [ConfigModule, ...],
})
export class AppModule {}
现在 @company/npm-common
被导入到 package.json 中 file:../npm-common
npm-common/index.ts
:
export * from './Config';
npm-common/Config/index.ts
export { ConfigService } from './config.service';
export { ConfigModule } from './config.module';
npm-common/Config/config.service
:
import { Global, Module } from '@nestjs/common';
import { ConfigService } from './config.service';
@Global()
@Module({
providers: [
{
provide: ConfigService,
useValue: new ConfigService(),
},
],
exports: [ConfigService],
})
export class ConfigModule {}
最佳答案
这个问题的愚蠢答案是主应用程序和外部模块加载了不同版本的 NestJS。从这个意义上说,版本 5.5 似乎与版本 6 不兼容。
关于typescript - 共享自定义 NestJS 模块出现 "not a part of the currently processed module"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55688331/
我是一名优秀的程序员,十分优秀!