2 votes

Nest can't resolve dependencies of the JwtService (?). Please make sure that the argument JWT_MODULE_OPTIONS

I am following the nest js documentation to do the authentication ( https://docs.nestjs.com/techniques/authentication ) and I get this error.

Nest can't resolve dependencies of the JwtService (?). Please make sure that the argument JWT_MODULE_OPTIONS at index [0] is available in the AppModule context.

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

My app.module.ts

    @Module({
      imports: [
        CustomerModule,
        TypeOrmModule.forRoot(dbconfig),
        AuthModule,
        UserModule
      ],
      controllers: [AppController],
      providers: [AppService, UserService , AuthService , JwtService],
    })
    export class AppModule {}

0 votes

How are you, were you able to solve it? I have the same problem.

0voto

OG Newbie Points 1

The same thing was happening to me just a while ago, I managed to fix it by removing the JwtService from providers and adding the JwtModule (either with .register() o .regirterAsync() ) a imports .

0voto

Alan Points 796

I was getting the same thing, it turns out that the error occurs when you use the different model name in the service when you inject it with the one you have in the module:

In this example case, the model: User that you use in the service must be called the same as the one you import in the Module, TypeOrmModule.forFeature any variation in the name of this as: Users or similar will give you this error, here is an example:

user.service.ts

constructor(@InjectRepository(User) private usersRepository: Repository<User> ){}

user.module.ts

@Module({
 imports: [TypeOrmModule.forFeature([User])],
 providers: [...],
 controllers: [...],
})

I leave you the reference page of the documentation

HolaDevs.com

HolaDevs is an online community of programmers and software lovers.
You can check other people responses or create a new question if you don't find a solution

Powered by:

X