Reputation: 71
I'm implementing an API on NestJS that will consume another API, I'm using @nestjs/axios.
I followed this tutorial: https://docs.nestjs.com/techniques/http-module
But when I start the project with yarn start:dev
It is throwing an exception as:
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 */ ]
})
My 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],
})
My axel-globe.module.ts
@Module({
controllers: [AxelGlobeController],
imports: [ConfigModule.forRoot(), HttpModule],
providers: [AxelGlobeService, HttpService],
})
My service.ts
constructor(private readonly httpService: HttpService) {}
Anyone can help me?
Upvotes: 7
Views: 12074
Reputation: 6665
drop that HttpService
of your providers
list. You just need to import HttpModule
in order to have HttpService
provider available to use. Follow the docs https://docs.nestjs.com/techniques/http-module#getting-started
Upvotes: 12