How to fix AXIOS_INSTANCE_TOKEN at index [0] is available in the Module context

Import HttpModule from @nestjs/common in TimeModule and add it to the imports array.

Remove HttpService from the providers array in TimeModule. You can directly import it in the TimeService.

import { HttpModule } from '@nestjs/common';
...

@Module({
    imports: [TerminalModule, HttpModule],
    providers: [TimeService],
    ...
})

TimeService:

import { HttpService } from '@nestjs/common';

If your response type is an Observable of type AxiosResponse, then import these two as well in the service file TimeService.

import { Observable } from 'rxjs';
import { AxiosResponse } from 'axios';

For reference, check out http-module and this post.

Leave a Comment

tech