[英]NestJS can't resolve dependencies of the JWT_MODULE_OPTIONS (Same problem, different solution)
This is not duplicate!这不是重复的! I saw same problem here , but solution not helped.
我在这里看到了同样的问题,但解决方案没有帮助。
My NestJS instance is not starting because of this problem:由于这个问题,我的 NestJS 实例没有启动:
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:我的 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):这是我的 app.module.ts(入口模块):
@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.我通过导入正确导入模块
imports: [ConfigModule]
,但仍然出现错误,注入失败,因为模块未导入。
My ConfigModule is 100% imported into app as my log say: ConfigModule dependencies initialized
正如我的日志所说,我的 ConfigModule 已 100% 导入到应用程序中:
ConfigModule dependencies initialized
What am I doing wrong?我究竟做错了什么?
The issue, assuming you are using the @nestjs/config
module, was a bug in the module's code for version < 0.2.3.假设您使用的是
@nestjs/config
模块,该问题是版本 < @nestjs/config
的模块代码中的一个错误。 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.如果您使用
npm i @nestjs/config@latest
升级到npm i @nestjs/config@latest
它应该可以正常运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.