我有一个循环依赖问题,但我不知道它是从哪里来的。整个错误消息如下:
Nest cannot create the module instance. Often, this is because of a circular dependency between modules. Use forwardRef() to avoid it.
(Read more: https://docs.nestjs.com/fundamentals/circular-dependency)
Scope [AppModule -> EntriesModule]因此,我猜在指定的模块之间存在循环依赖问题,即AppModule和EntriesModule。EntriesModule位于AppModule模块的imports中,如下所示:
@Module({
providers: [
EntryService,
IsUniqueEntryTitle,
],
imports: [
AwsModule,
TypeOrmModule.forFeature([
EntryEntity,
CategoryEntity,
]),
CategoriesModule,
SharedModule,
],
controllers: [
EntryController,
],
exports: [
EntryService,
],
})
export class EntriesModule {}据我所知,当模块A依赖于模块B,而模块B又依赖于模块A时,就会抛出循环依赖错误。换句话说,它们的导入中都有彼此。但这里似乎不是这样。为什么我会得到这个错误呢?
发布于 2020-06-26 01:21:02
哦,我知道我做错了什么。我忘了删除头文件中的import语句。我只是从模块的装饰器的imports部分中删除了它。
https://stackoverflow.com/questions/62580221
复制相似问题