javascript - NestJS 无法解决 JWT_MODULE_OPTIONS 的依赖关系(同样的问题,不同的解决方案)
问题描述
这不是重复的!我在这里看到了同样的问题,但解决方案没有帮助。
由于这个问题,我的 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.
我的 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 {}
这是我的 app.module.ts(入口模块):
@Module({
imports: [
ConfigModule.forRoot({
envFilePath: '.development.env',
}),
AuthModule,
UserModule,
DatabaseModule,
],
})
export class AppModule {}
我通过 正确导入模块imports: [ConfigModule]
,但仍然出现错误,注入失败,因为未导入模块。
正如我的日志所说,我的 ConfigModule 已 100% 导入到应用程序中:ConfigModule dependencies initialized
我究竟做错了什么?
解决方案
假设您正在使用该@nestjs/config
模块,该问题是版本 < 0.2.3 的模块代码中的错误。在最新版本中,该问题已得到修复。如果您升级到 0.2.3,npm i @nestjs/config@latest
它应该可以正常运行。
推荐阅读
- delphi - Delphi App 从 Delphi 10 Seattle 升级到 Delphi 13.3.3 Rio - 带有空格的 SQL Server Db 列在 ClientDataSet 和 SimpleDataSet 中不起作用
- java - 如何永久阻止 JavaFX 代码在 Eclipse 中被突出显示为错误?
- c# - 如果满足条件,从列表中删除行的方法
- python - .NoReverseMatch:未找到带有参数“(”,)“的“作者详细信息”的反向。尝试了 1 种模式:['catalog/author/(?P
[0-9]+)$'] - kubernetes - 在 kubernetes 中使用 traefik v2 添加基本身份验证未弹出登录表单
- sql - 使用 SAS 在同一列中进行条件减法
- java - java/JSON 未显示解析 JSON 所需的值
- docker - Fluentd 日志驱动程序标记设置不起作用
- python - python matplotlib如何绘制20个或所需的数字唯一和不同的颜色而不是渐变颜色
- c++ - 在 float[4] 和 qbytearray 之间转换