Search code examples
nestjstypeorm

Nestjs cannot resolve dependency index[0] when decorator is being used


I am new to NestJs and i have a question for you that i could not resolve it.

UsersService has two dependencies

-TypeOrm UsersRepository Injection -WalletsService Injection

Typeorm injection is done by decorator as you see down below.

//UsersService
@Injectable()
export class UsersService implements IUserService {
  constructor(
    @InjectRepository(Users)
    private usersRepository: Repository<Users>,
    private readonly walletsService: WalletsService,
  ) { }

Whenever i changed first injection it cannot be resolved.

Probably i am missing something. There are all photos down below with description

//UsersModule
@Module({
  controllers: [UsersController],
  exports: [UsersService],
  imports: [WalletsModule, TypeOrmModule.forFeature([Users])],
  providers: [UsersService],
})

export class UsersModule { }

//WalletsModule
@Module({
  controllers: [WalletsController],
  exports: [WalletsService],
  imports: [TypeOrmModule.forFeature([Wallets])],
  providers: [WalletsService]
})

export class WalletsModule { }

[When Users Repository is first injection]

Nest can't resolve dependencies of the UsersService (?, WalletsService). Please make sure that the argument UsersRepository at index [0] is available in the UsersService context.

Potential solutions:
- If UsersRepository is a provider, is it part of the current UsersService?
- If UsersRepository is exported from a separate @Module, is that module imported within UsersService?
  @Module({
    imports: [ /* the Module containing UsersRepository */ ]
  })

[When Wallets Service is first injection ]

Nest can't resolve dependencies of the UsersService (?, UsersRepository). Please make sure that the argument WalletsService at index [0] is available in the UsersService context.

Potential solutions:
- If WalletsService is a provider, is it part of the current UsersService?
- If WalletsService is exported from a separate @Module, is that module imported within UsersService?
  @Module({
    imports: [ /* the Module containing WalletsService */ ]
  })

Thank you in advance. I hope it is descriptive enough. Have good day!


Solution

  • For posterity of the answer from the comments:

    There was a service in an imports array which leads to problems with Nest trying to resolve things. In general, these errors can start to be debugged knowing that Nest's error is in the form of

    Nest can't resolve dependencies of the UsersService (<dependencies_with_unknown_as_?>. Please make sure that the argument <unknown_dependency> at index [] is available in the <related_module> context.