Nest 无法解析 AuthService (?) 的依赖项。请确保索引 [0] 处的参数在 AuthModule 上下文中可用。+134ms 错误:Nest 无法解析 AuthService (?) 的依赖关系。请确保索引 [0] 处的参数在 AuthModule 上下文中可用。
我从https://docs.nestjs.com/techniques/authentication复制了代码,然后报了这个错误:
import { Injectable, Inject } from '@nestjs/common';
import { UsersService } from '../users/users.service';
@Injectable()
export class AuthService {
//constructor(private readonly usersService: UsersService) {}
constructor(@Inject('UsersService') private UsersService: UsersService) {}
async validateUser(token: string): Promise<any> {
// Validate if token passed along with HTTP request
// is associated with any registered account in the database
return await this.UsersService.findOneByToken(token);
}
}
Run Code Online (Sandbox Code Playgroud)
import { …Run Code Online (Sandbox Code Playgroud) Nest无法解析AuthService(?)的依赖项。请验证[0]参数在当前上下文中是否可用。
请找到我的项目资料库
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] …Run Code Online (Sandbox Code Playgroud)