Reputation: 3714
This is not duplicate! I saw same problem here, but solution not helped.
My NestJS instance is not starting because of this problem:
Nest can't resolve dependencies of the JWT_MODULE_OPTIONS (?). Please make sure that the argument ConfigService at index [0] is available in the JwtModule context.
My auth.module.ts:
@Module({
imports: [
TypeOrmModule.forFeature([User, Token]),
DatabaseModule,
UserModule,
ConfigModule,
PassportModule,
JwtModule.registerAsync({
imports: [ConfigModule], // Missing this
useFactory: async (configService: ConfigService) => ({
signOptions: {
expiresIn: configService.get<string>('JWT_EXPIRATION'),
},
secretOrPrivateKey: configService.get<string>('JWT_SECRET'),
}),
inject: [ConfigService],
}),
],
controllers: [AuthController],
providers: [AuthService, LocalStrategy],
})
export class AuthModule {}
and this is my app.module.ts (Entry Module):
@Module({
imports: [
ConfigModule.forRoot({
envFilePath: '.development.env',
}),
AuthModule,
UserModule,
DatabaseModule,
],
})
export class AppModule {}
I am importing module correctly by imports: [ConfigModule]
, but still I am getting error, that injection failed, because module is not imported.
My ConfigModule is 100% imported into app as my log say: ConfigModule dependencies initialized
What am I doing wrong?
Upvotes: 1
Views: 667
Reputation: 70221
The issue, assuming you are using the @nestjs/config
module, was a bug in the module's code for version < 0.2.3. In the latest version there was a fix to the issue. If you upgrade to 0.2.3 with npm i @nestjs/config@latest
it should run fine.
Upvotes: 1