【发布时间】:2020-12-13 19:05:15
【问题描述】:
我正在关注此处提供的文档
https://docs.nestjs.com/techniques/authentication#jwt-functionality
为了获得更快的支持,我创建了一个有问题的 git 存储库
https://github.com/Sano123456/nestjs-jwt
node -v -> v10.15.2
npm -v -> 6.14.6
nest -v -> 7.4.1
第一个问题: 在 AuthModule 中,如果我按照文档中的说明进行操作并仅导入 UserModule,则会返回 UserModule 和 AuthModule 之间循环依赖的错误
@Module({
imports:[
UsersModule,
PassportModule
],
providers: [AuthService],
controllers: [AuthController],
exports:[AuthService, LocalStrategy]
})
export class AuthModule {}
错误:
[ExceptionHandler] Nest cannot create the AuthModule instance.
The module at index [0] of the AuthModule "imports" array is undefined.
Potential causes:
- A circular dependency between modules. Use forwardRef() to avoid it. Read more: https://docs.nestjs.com/fundamentals/circular-dependency
- The module at index [0] is of type "undefined". Check your import statements and the type of the module.
Scope [AppModule -> UsersModule] +6ms
可能的解决方案在 AuthModule 的导入数组中而不是 UserModule 中提出Ref(() => UsersModule), 这实际上消除了错误,但不确定这是否是正确的方法
第二个问题: 它说即使它存在并在 AuthModule 中声明也找不到 LocalStrategy 类
[ExceptionHandler] Nest cannot export a provider/module that is not a part of the currently processed module (AuthModule). Please verify whether the exported LocalStrategy is available in this particular context.Is LocalStrategy part of the relevant providers/imports within AuthModule?
可能的解决方案现在我没有任何解决方案,我只是将其删除以了解问题所在
第三个问题: 移除 LocalStrategy 后,
[ExceptionHandler] Nest can't resolve dependencies of the AuthService (?). Please make sure that the argument dependency at index [0] is available in the AuthModule context.
Potential solutions:
- If dependency is a provider, is it part of the current AuthModule?
- If dependency is exported from a separate @Module, is that module imported within AuthModule?
@Module({
imports: [ /* the Module containing dependency */ ]
})
+1ms
Error: Nest can't resolve dependencies of the AuthService (?). Please make sure that the argument dependency at index [0] is available in the AuthModule context.
有人解决了这个问题吗?
【问题讨论】:
-
你提到的问题是什么?
标签: nestjs nestjs-passport nestjs-jwt