Gordana Tasic

Gordana Tasic

  • 2k
  • 63
  • 2.9k

Error: Nest cannot create the TeamsModule instance.

Aug 17 2021 3:08 PM

When I start Nest.js app, error occured: "Nest cannot create the TeamsModule instance.The module at index [3] of the TeamsModule "imports" array is undefined." Here is the code:

@Module({
  imports: [TypeOrmModule.forFeature([Selector]), SportsModule, FacultiesModule, TeamsModule],
  controllers: [SelectorsController],
  providers: [SelectorsService],
  exports: [TypeOrmModule, SelectorsService]
})
export class SelectorsModule {}

@Injectable()
export class SelectorsService
{
    constructor(@InjectRepository(Selector) private selectorsRepository: Repository<Selector>,
                private sportsService: SportsService, private facultiesService: FacultiesService,
                @Inject(forwardRef(() => TeamsService)) private teamsService: TeamsService)
    {
    }
}

@Module({
  imports: [TypeOrmModule.forFeature([Team]), SportsModule, FacultiesModule, SelectorsModule],
  controllers: [TeamsController],
  providers: [TeamsService],
  exports: [TypeOrmModule, TeamsService]
})
export class TeamsModule {}

@Injectable()
export class TeamsService
{
    constructor(@InjectRepository(Team) private teamsRepository: Repository<Team>,
                private sportsService: SportsService, private facultiesService: FacultiesService,
                @Inject(forwardRef(() => SelectorsService)) private selectorsService: SelectorsService)
    {
    }
}

I applied everything to avoid Circular dependency, but it still doesn't work. Does anyone know how to solve this. Thanks in advance.