【问题标题】:Nest js cannot resolve dependencies. in Auth serviceNest js 无法解析依赖关系。在身份验证服务中
【发布时间】:2018-12-09 23:38:35
【问题描述】:

Nest 无法解析 AuthService (?) 的依赖关系。请验证 [0] 参数在当前上下文中是否可用。

请找到我的项目存储库

Nest-auth-test

Error: Nest can't resolve dependencies of the AuthService (?). Please verify whether [0] argument is available in the current context.
    at Injector.lookupComponentInExports (/home/arpit/Documents/aquaapp/node_modules/@nestjs/core/injector/injector.js:129:19)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:182:7)
    at Function.Module.runMain (internal/modules/cjs/loader.js:697:11)
    at Object.<anonymous> (/home/arpit/Documents/aquaapp/node_modules/ts-node/src/_bin.ts:177:12)
    at Module._compile (internal/modules/cjs/loader.js:654:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
    at Module.load (internal/modules/cjs/loader.js:566:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
    at Function.Module._load (internal/modules/cjs/loader.js:498:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:695:10)
    at startup (internal/bootstrap/node.js:201:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:516:3)
 1: node::Abort() [/usr/bin/node]
 2: 0x8d04d9 [/usr/bin/node]
 3: v8::internal::FunctionCallbackArguments::Call(void (*)(v8::FunctionCallbackInfo<v8::Value> const&)) [/usr/bin/node]
 4: 0xb17d2c [/usr/bin/node]
 5: v8::internal::Builtin_HandleApiCall(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/bin/node]
 6: 0x2176d1e042fd
Aborted (core dumped)

【问题讨论】:

    标签: authentication jwt nestjs


    【解决方案1】:

    通常当您遇到此类异常时,是因为您试图注入另一个模块的依赖项并且该依赖项尚未导出到导出数组中。这是一个示例:

    假设您在模块 A 中有一些服务要在模块 B 中使用:

    @Injectable()
    export class SampleService {}
    
    @Module({
      exports: [SampleService]
    })
    export class ModuleA {}
    
    @Module({
      imports: [ModuleA]
    })
    export class ModuleB {}
    

    请记住,如果在 ModuleB 中导入 ModuleA,在 ModuleA 中导入 ModuleB,则会出现循环依赖错误。

    【讨论】:

    • 我已经导出了。并注入 [服务,控制器]。您可以在 gitlab 上查看我的代码。谢谢你帮助我。
    • 我可以在您的 auth.module 中看到您没有导入:[UserModule].. 您也可以在 github 上使用 nest 和 angular 检查我的项目github.com/bojidaryovchev/nest-angular
    • 谢谢。 Божидар Йовчев 回复.. 我试过 [imported usermodule] 那个。但我遇到了同样的错误。
    • 在您的user.module.ts 中,您没有export UserService 并且您在AuthModule 中没有import UserModule
    • 谢谢@ChauTran 和Божидар Йовчев。为了帮助我。现在它工作正常。
    猜你喜欢
    • 2019-06-29
    • 1970-01-01
    • 2021-04-20
    • 1970-01-01
    • 1970-01-01
    • 2019-02-24
    • 2021-07-17
    • 2022-01-17
    • 2018-11-21
    相关资源
    最近更新 更多