Nest 无法解析 HttpService 的依赖关系(?)。请确保参数 AXIOS_INSTANCE_TOKEN 位于索引 [0]

Mat*_*nto 4 nestjs

我正在 NestJS 上实现一个 API,它将使用另一个 API,我正在使用 @nestjs/axios。

我遵循了本教程: https: //docs.nestjs.com/techniques/http-module

但是当我开始项目时yarn start:dev

它抛出一个异常:

ERROR [ExceptionHandler] Nest can't resolve dependencies of the HttpService (?). Please make sure that the argument AXIOS_INSTANCE_TOKEN at index [0] is available in the AxelGlobeModule context.

Potential solutions:
- If AXIOS_INSTANCE_TOKEN is a provider, is it part of the current AxelGlobeModule?
- If AXIOS_INSTANCE_TOKEN is exported from a separate @Module, is that module imported within AxelGlobeModule?
  @Module({
    imports: [ /* the Module containing AXIOS_INSTANCE_TOKEN */ ]
  })
Run Code Online (Sandbox Code Playgroud)

我的app.module.ts

@Module({
  imports: [
    FileModule,
    ConfigurationModule,
    AxelGlobeModule,
    HttpModule.registerAsync({
      imports: [ConfigModule],
      useFactory: async (configService: ConfigService) => ({
        timeout: configService.get('HTTP_TIMEOUT') || 1000,
        maxRedirects: configService.get('HTTP_MAX_REDIRECTS') || 5,
        baseURL: `{url}`,
        paramsSerializer: (params) => {
          return qs.stringify(
            params,
            PARAMS_SERIALIZER_DEFAULT_OPTIONS as IStringifyOptions,
          );
        },
      }),
      inject: [ConfigService],
    }),
  ],
  controllers: [AppController],
  providers: [AppService, HttpModule, HttpService],
  exports: [HttpModule],
})
Run Code Online (Sandbox Code Playgroud)

我的 axel-globe.module.ts

@Module({
  controllers: [AxelGlobeController],
  imports: [ConfigModule.forRoot(), HttpModule],
  providers: [AxelGlobeService, HttpService],
}) 
Run Code Online (Sandbox Code Playgroud)

我的服务.ts

constructor(private readonly httpService: HttpService) {}
Run Code Online (Sandbox Code Playgroud)

有人可以帮助我吗?

Mic*_*evi 11

删除HttpService你的providers列表中的那个。您只需导入HttpModule即可让HttpService提供程序可供使用。按照文档https://docs.nestjs.com/techniques/http-module#getting-started