共享自定义NestJS模块提供“不是当前处理模块的一部分”错误

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

我们正在为不同的服务运行几个NestJS应用程序。它们都共享一些公共代码,在我们的例子中是ConfigModule和CacheModule。我想打破这些并将它们放在公司的“通用”npm包中,以便最大限度地减少代码复制。

我遇到了一个错误:Nest cannot export a component/module that is not a part of the currently processed module (ConfigModule). Please verify whether each exported unit is available in this particular contex

关于问题到底是什么,我有点迷茫。任何帮助深表感谢。

app.ts服务A:

import { ConfigModule } from '@company/npm-common';
...
@Module({
  imports: [ConfigModule, ...],
})
export class AppModule {}

现在@company/npm-common是用file:../npm-common在package.json中导入的

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 {}
typescript nestjs
1个回答
0
投票

这个问题的愚蠢答案是主应用程序和外部模块加载了不同版本的NestJS。似乎5.5版本在这个意义上与版本6不兼容。

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