Every time I try to run my project, I get the error:
CircularDependencyException [Error]: A circular dependency has been detected inside @InjectRepository(). Please, make sure that each side of a bidirectional relationships are decorated with "forwardRef()". Also, try to eliminate barrel files because they can lead to an unexpected behavior too.
The only clue I have is one of my modules:
If I comment this line:
constructor(
@InjectRepository(Role) private roleRepo: Repository<Role>
){}
and the project runs, but I notice the log when I start the project, the Module with the error starts before everything
[Nest] 16872 - 08/04/2020, 7:56:24 PM [NestFactory] Starting Nest application...
[Nest] 16872 - 08/04/2020, 7:56:24 PM [InstanceLoader] TypeOrmModule dependencies initialized +91ms
[Nest] 16872 - 08/04/2020, 7:56:25 PM [InstanceLoader] MyErrorModule dependencies initialized +500ms
[Nest] 16872 - 08/04/2020, 7:56:25 PM [InstanceLoader] TypeOrmCoreModule dependencies initialized +630ms
[Nest] 16872 - 08/04/2020, 7:56:25 PM [InstanceLoader] TypeOrmModule dependencies initialized +2ms
[Nest] 16872 - 08/04/2020, 7:56:25 PM [InstanceLoader] TypeOrmModule dependencies initialized +1ms
[Nest] 16872 - 08/04/2020, 7:56:25 PM [InstanceLoader] TypeOrmModule dependencies initialized +1ms
[Nest] 16872 - 08/04/2020, 7:56:25 PM [InstanceLoader] TypeOrmModule dependencies initialized +1ms
[Nest] 16872 - 08/04/2020, 7:56:25 PM [InstanceLoader] TypeOrmModule dependencies initialized +4ms
[Nest] 16872 - 08/04/2020, 7:56:25 PM [InstanceLoader] AuthorizationModule dependencies initialized +3ms
[Nest] 16872 - 08/04/2020, 7:56:25 PM [InstanceLoader] AppModule dependencies initialized +3ms
[Nest] 16872 - 08/04/2020, 7:56:25 PM [InstanceLoader] FirstModule dependencies initialized +2ms
But I have my app.module.ts file with
@Module({
imports: [TypeOrmModule.forRootAsync({
useClass: DatabaseConnectionService
}),
AuthorizationModule,
TypeOrmModule.forFeature([User, Role]),
FirstModule,
SecondModule,
MyErrorModule, //This is the first to be executed
],
Someone has an idea about how to solve this issue?