gpt4 book ai didi

nestjs - Nest 无法解析 HttpService 的依赖项(?)。请确保索引 [0] 处的参数 AXIOS_INSTANCE_TOKEN

转载 作者:行者123 更新时间:2023-12-01 23:09:55 30 4
gpt4 key购买 nike

我正在 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 */ ]
})

我的 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],
})

我的 axel-globe.module.ts

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

我的服务.ts

constructor(private readonly httpService: HttpService) {}

谁能帮帮我?

最佳答案

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

关于nestjs - Nest 无法解析 HttpService 的依赖项(?)。请确保索引 [0] 处的参数 AXIOS_INSTANCE_TOKEN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70096543/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com