简体   繁体   English

NestJS Axios 模块 - 无法解决依赖关系

[英]NestJS Axios module - can't resolve dependencies

I'm having a baffling problem with the NestJS Axios module.我对 NestJS Axios 模块有一个莫名其妙的问题。 I have it imported in my module like so:我将它导入到我的模块中,如下所示:

import { Module } from '@nestjs/common';
import { HttpModule } from '@nestjs/axios';
import { PassportModule } from '@nestjs/passport';

import { AuthController } from './auth.controller';
import { AuthService } from './auth.service';
import { AuthStrategy } from './auth.strategy';

@Module({
  controllers: [AuthController],
  providers: [AuthService],
  imports: [HttpModule, PassportModule, AuthStrategy],
})

And I'm attempting to use it in my AuthStrategy like so:我试图在我的AuthStrategy中使用它,如下所示:

import { PassportStrategy } from '@nestjs/passport';
import { Injectable } from '@nestjs/common';
import { HttpService } from '@nestjs/axios';
import { Strategy } from 'passport-oauth2';

@Injectable()
export class AuthStrategy extends PassportStrategy(Strategy) {
  constructor(private readonly httpService: HttpService) {
    super({
      authorizationURL: `${process.env['OAUTH_DOMAIN']}/authorize`,
      tokenURL: `${process.env['OAUTH_DOMAIN']}/oauth/token`,
      clientID: process.env['OAUTH_CLIENT_ID'],
      clientSecret: process.env['OAUTH_CLIENT_SECRET'],
      callbackURL: process.env['OAUTH_REDIRECT_URL'],
      scope: ['openid', 'email', 'profile'],
    });
  }

  async validate(accessToken: string): Promise<any> {
    const data = await this.httpService.get(`${process.env['OAUTH_DOMAIN']}/`, {
      headers: { Authorization: `Bearer ${accessToken}` },
    });

    console.log(data);
  }
}

But I get the error:但我得到了错误:

Error: Nest can't resolve dependencies of the AuthStrategy (?). Please make sure that the argument HttpService at index [0] is available in the AuthStrategy context.

Where am I going wrong?我哪里错了? I've done what the error suggests, but it's still not working我已经完成了错误提示的操作,但仍然无法正常工作

Somewhere in your application, you have AuthStrategy (a provider) added to a module's imports array.在您的应用程序的某处,您将AuthStrategy (提供程序)添加到模块的imports数组中。 Providers should never be in the imports arrays.提供者永远不应该在imports arrays 中。

You can learn more about reading and dissecting the error message from the docs page .您可以从文档页面了解有关阅读和剖析错误消息的更多信息。

There are a few gotchas, that are common.有一些陷阱,很常见。 One is putting a provider in an imports array.一种是将提供者放入imports数组中。 If this is the case, the error will have the provider's name where <module> should be.如果是这种情况,错误将包含提供程序的名称,其中<module>应该是。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 NestJS无法解析AuthServices的依赖项 - NestJS can't resolve dependencies of the AuthServices Nestjs 无法解析 XModel 的依赖关系 - Nestjs can't resolve dependencies of XModel NestJs 无法解析 HeicService 的依赖关系 - NestJs can't resolve dependencies of the HeicService NestJS Nest无法解析RolesService的依赖关系(+,+ ,?) - NestJS Nest can't resolve dependencies of the RolesService (+, +, ?) Nestjs - 无法解决服务的依赖关系 - Nestjs - Can't resolve dependencies of service 无法在 NestJs 服务上创建 Jest 测试模块。 获取 Nest 无法解析 UsersService (?, ConfigService) 的依赖关系 - Unable to create Jest testing module on NestJs service. Geting Nest can't resolve dependencies of the UsersService (?, ConfigService) 未找到 REACTJS 模块:无法解析“axios” - REACTJS Module not found: Can't resolve 'axios' NestJS - Nest 无法解析 ConfigurationService 的依赖项(ConfigService,?) - NestJS - Nest can't resolve dependencies of the ConfigurationService (ConfigService, ?) 问题 nestjs - Nest 无法解析 AuthenticationService 的依赖项(?) - problem nestjs - Nest can't resolve dependencies of the AuthenticationService (?) NestJs 无法解决循环依赖的服务依赖 - NestJs can't resolve service dependencies on a circular dependency
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM