javascript - NestJS无法解析JWT_MODULE_OPTIONS的依赖关系(同样的问题,不同的解决方案)

标签 javascript typescript module nestjs nestjs-config

这不是重复的!我看到同样的问题here ,但解决方案没有帮助。

由于此问题,我的 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] 正确导入模块,但仍然收到错误,注入(inject)失败,因为模块未导入。

我的 ConfigModule 已 100% 导入到应用程序中,正如我的日志所示:ConfigModule 依赖项已初始化

我做错了什么?

最佳答案

假设您使用的是 @nestjs/config 模块,该问题是版本 < 0.2.3 的模块代码中的错误。 In the latest version该问题已得到解决。如果您使用 npm i @nestjs/config@latest 升级到 0.2.3,它应该可以正常运行。

关于javascript - NestJS无法解析JWT_MODULE_OPTIONS的依赖关系(同样的问题,不同的解决方案),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60174840/

相关文章:

javascript - 有没有一种简单的方法可以将数字拆分为数字数组而不将其转换为字符串并返回?

angularjs - 将 Mongoose 模型表示为 Typescript 类

zend-framework - 如何在基于 Zend Framework 的应用程序中的应用程序 Bootstrap 中使用模块中的模型类?

module - 在单个 Jest 测试中模拟多个模块

javascript - 使窗口在 Chrome 中不可调整大小

javascript - 在 express 路由器和中间件之间传递数据

javascript - 在 highcharts 中,如何更改类别上方线条的颜色?

angular - 更新到 NG9 后,自定义类注释在生产版本中不起作用

javascript - 将 API 请求从使用 Promise 迁移到 Observable(使用 axios)

iis-6 - 未在 GetRouteData (System.Web.Routing) 中设置对象引用