Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

576
Visualizações
NestJs cannot istantiate module (circular dependencies error?)

I have two modules which depend on each other.

GameModule.ts

import { Module, CacheModule, Global } from '@nestjs/common';
import { GameController } from './game.controller';
import { GameService } from './game.service';
import { PlayerModule } from '@src/player/player.module';

@Global()
@Module({
  imports: [
    CacheModule.register(),
    PlayerModule,
  ],
  controllers: [GameController],
  providers: [GameService],
  exports: [CacheModule, GameService],
})
export class GameModule {}

PlayerModule.ts

import { Module, Global } from '@nestjs/common';
import { PlayerController } from './player.controller';
import { PlayerService } from './player.service';
import { GameModule } from '@src/game/game.module';
import { Web3ManagerModule } from '@src/web3-manager/web3-manager.module';

@Global()
@Module({
  imports: [GameModule, Web3ManagerModule],
  controllers: [PlayerController],
  providers: [PlayerService],
  exports: [PlayerService],
})
export class PlayerModule {}

I defined in their services the other one with forwardRef

GameService.ts

...
constructor(
    @Inject(CACHE_MANAGER) private cacheManager: Cache,
    @Inject(forwardRef(() => PlayerService))
    private playerService: PlayerService,
  ) {
...

PlayerService.ts

...
constructor(
    @Inject(forwardRef(() => GameService))
    private gameService: GameService,
    private web3Manager: Web3ManagerService,
  ) {
...

but I keep getting the error:

Nest cannot create the GameModule instance.
The module at index [1] of the GameModule "imports" array is undefined.
Potential causes:
- A circular dependency between modules. Use forwardRef() to avoid it. Read more: https://docs.nestjs.com/fundamentals/circular-dependency
- The module at index [1] is of type "undefined". Check your import statements and the type of the module.

What am I missing?

about 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda