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

Created on 10 Oct 2018  路  6Comments  路  Source: nestjs/nest

I'm submitting a...


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior


I get:

[Nest] 4578   - 10/10/2018, 4:43:26 PM   [ExceptionHandler] Nest can't resolve dependencies of the HttpService (?). Please make sure that the argument at index [0] is available in thecurrent context. +24ms

Expected behavior


The app should run just fine and the HttpService dependency can be injected in the AppModule.

Minimal reproduction of the problem with instructions


Install cli and perform the following steps:

  1. run nest new app
  2. edit app.module.ts (import HttpService from HttpModule), code diff
import { Module, HttpService, HttpModule } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';

@Module({
  imports: [HttpModule],
  controllers: [AppController],
  providers: [AppService, HttpService],
})
export class AppModule {}
  1. run npm run start

    What is the motivation / use case for changing the behavior?


I would like to make some http requests in the nest app (download some files and then process them)

Environment


Nest version: 5.1.0


For Tooling issues:
- Node version: v10.9.0  
- Platform:  Mac 

Others:

Most helpful comment

hey fixed this yet?
if not, you don't need to set HttpService as a provider, only the HttpModule as a import. the HttpService is injected in the provider you're going to use.
image from the docs.
screenshot from 2018-10-10 19-46-54
screenshot from 2018-10-10 19-47-19

All 6 comments

hey fixed this yet?
if not, you don't need to set HttpService as a provider, only the HttpModule as a import. the HttpService is injected in the provider you're going to use.
image from the docs.
screenshot from 2018-10-10 19-46-54
screenshot from 2018-10-10 19-47-19

@barretojs thanks. I updated from nestjs major version 4, and for some reason, I had the HttpService listed in the providers. Nest-js version 4 won't complain about this.
Thanks again, closing the issue

I am getting the same error and have followed the above suggestions.

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

at Injector.lookupComponentInExports (/project/node_modules/@nestjs/core/injector/injector.js:144:19)

Here is the BitcoinService file:

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

@Injectable()
export class BitcoinService {

    constructor(private http: HttpService) {

}

Here is the AppModule:

import { Module, HttpModule} from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { BitcoinController } from './bitcoin/bitcoin.controller';
import { BitcoinService } from './services/bitcoin.service';

@Module({
  imports: [HttpModule],
  controllers: [AppController, BitcoinController],
  providers: [AppService, BitcoinService],
})
export class AppModule {}

[System Information]
OS Version : macOS High Sierra
NodeJS Version : v11.0.0
NPM Version : 6.4.1
[Nest Information]
common version : 5.4.0
core version : 5.4.0

Hi werewolf,
My issue was due to the missing reference.

I guess you would need to include 'BitcoinService' ref in your module. I had a separate ts file. so I just included it with the @Module ({components: [HERE_IT_GOES],}). Hope it helps.

I am getting the same error and have followed the above suggestions.

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

at Injector.lookupComponentInExports (/project/node_modules/@nestjs/core/injector/injector.js:144:19)

Here is the BitcoinService file:

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

@Injectable()
export class BitcoinService {

    constructor(private http: HttpService) {

}

Here is the AppModule:

import { Module, HttpModule} from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { BitcoinController } from './bitcoin/bitcoin.controller';
import { BitcoinService } from './services/bitcoin.service';

@Module({
  imports: [HttpModule],
  controllers: [AppController, BitcoinController],
  providers: [AppService, BitcoinService],
})
export class AppModule {}

[System Information]
OS Version : macOS High Sierra
NodeJS Version : v11.0.0
NPM Version : 6.4.1
[Nest Information]
common version : 5.4.0
core version : 5.4.0

I am getting the same error and have followed the above suggestions.

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

at Injector.lookupComponentInExports (/project/node_modules/@nestjs/core/injector/injector.js:144:19)

Here is the BitcoinService file:

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

@Injectable()
export class BitcoinService {

    constructor(private http: HttpService) {

}

Here is the AppModule:

import { Module, HttpModule} from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { BitcoinController } from './bitcoin/bitcoin.controller';
import { BitcoinService } from './services/bitcoin.service';

@Module({
  imports: [HttpModule],
  controllers: [AppController, BitcoinController],
  providers: [AppService, BitcoinService],
})
export class AppModule {}

[System Information]
OS Version : macOS High Sierra
NodeJS Version : v11.0.0
NPM Version : 6.4.1
[Nest Information]
common version : 5.4.0
core version : 5.4.0

@werewolfe, i was facing the same issues but this worked for me.
change your imports section to look like :

imports: [HttpModule.register({
      timeout: 5000,
      maxRedirects: 5,
    }),],

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings