The official doc is not clear about how modules in nestjs work and I'm having a problem with a circular dependency. It seems like my module structure is messed up I would like to understand what is wrong with it. The error I'm getting reads:
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 -> UsersModule -> CategoriesModule]
Here are the import parts of all the modules mentioned in the error message.
AppModule:
UsersModule,
SmsRegistrationModule,
AuthModule,
SubscriptionModule,
EmailModule,
EntriesModule,
CategoriesModule,
AwsModule,
SharedModule
UsersModule:
CategoriesModule
CategoriesModule:
AwsModule,
SharedModule,
The error raised when I added SharedModule to the CategoriesModule module. Seems like I'm missing something on how these modules communicate and thus can't resolve this error.
Your help would be much apprecicted.
EDIT:
SharedModule:
@Module({
providers: [
CacheService,
CodeGenService,
IsUniqueEmail,
BasicFileService,
],
imports: [
CacheModule.registerAsync({
imports: [ConfigModule],
useClass: CacheConfigService,
}),
UsersModule,
AwsModule,
],
exports: [
CacheService,
CodeGenService,
IsUniqueEmail,
BasicFileService,
],
})
export class SharedModule {}
SharedModulehave in terms of import modules? - Jay McDonielSharedModule, please, have a look. - Albert