angular: Error: NullInjectorError: No provider for Http! ; Zone: ; while upgrading from version 4.4 to 5.

I’m submitting a…


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

While upgrading my angular application from version 4.4 to version 5 I’m getting the following error:

zone.js:690 Unhandled Promise rejection: StaticInjectorError[Http]: 
  StaticInjectorError[Http]: 
    NullInjectorError: No provider for Http! ; Zone: <root> ; Task: Promise.then ; Value: Error: StaticInjectorError[Http]: 
  StaticInjectorError[Http]: 
    NullInjectorError: No provider for Http!
    at _NullInjector.get (core.js:923)
    at resolveToken (core.js:1211)
    at tryResolveToken (core.js:1153)
    at StaticInjector.get (core.js:1024)
    at resolveToken (core.js:1211)
    at tryResolveToken (core.js:1153)
    at StaticInjector.get (core.js:1024)
    at resolveNgModuleDep (core.js:10584)
    at _createClass (core.js:10621)
    at _createProviderInstance$1 (core.js:10595) Error: StaticInjectorError[Http]: 
  StaticInjectorError[Http]: 
    NullInjectorError: No provider for Http!
    at _NullInjector.get (webpack-internal:///../../../core/esm5/core.js:1119:19)
    at resolveToken (webpack-internal:///../../../core/esm5/core.js:1407:24)
    at tryResolveToken (webpack-internal:///../../../core/esm5/core.js:1349:16)
    at StaticInjector.get (webpack-internal:///../../../core/esm5/core.js:1220:20)
    at resolveToken (webpack-internal:///../../../core/esm5/core.js:1407:24)
    at tryResolveToken (webpack-internal:///../../../core/esm5/core.js:1349:16)
    at StaticInjector.get (webpack-internal:///../../../core/esm5/core.js:1220:20)
    at resolveNgModuleDep (webpack-internal:///../../../core/esm5/core.js:10780:25)
    at _createClass (webpack-internal:///../../../core/esm5/core.js:10817:29)
    at _createProviderInstance$1 (webpack-internal:///../../../core/esm5/core.js:10791:26)
api.onUnhandledError @ zone.js:690

Of course I’ve already updated my Http to HttpClient and HttpModule to HttpClient module.

I guess it’s coming from @angular/platform-server/esm5/platform-server.js as I also see these two imports:

import { HTTP_INTERCEPTORS, HttpBackend, HttpClientModule, HttpHandler, XhrFactory, ɵinterceptingHandler } from '@angular/common/http';
import { BrowserXhr, Http, HttpModule, ReadyState, RequestOptions, XHRBackend, XSRFStrategy } from '@angular/http';

I imagine it may be caused by the fact that Http, HttpModule have to be imported from @angular/common/http now.

I’m using Angular CLI 1.5.0, this is my package.json:

. . .
"dependencies": {
    "@angular/animations": "^5.0.0",
    "@angular/common": "^5.0.0",
    "@angular/compiler": "^5.0.0",
    "@angular/core": "^5.0.0",
    "@angular/forms": "^5.0.0",
    "@angular/http": "^5.0.0",
    "@angular/platform-browser": "^5.0.0",
    "@angular/platform-browser-dynamic": "^5.0.0",
    "@angular/platform-server": "^5.0.0",
    "@angular/router": "^5.0.0",
    "core-js": "2.4.1",
    "rxjs": "^5.5.2",
    "zone.js": "^0.8.14",
   . . .
}, 
"devDependencies": {
    "@angular/cli": "^1.5.0",
    "@angular/compiler-cli": "^5.0.0",
    "@angular/language-service": "^5.0.0",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "codelyzer": "~3.2.0",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "ts-node": "~3.2.0",
    "tslint": "~5.7.0",
    "typescript": "^2.4.2"
}

Environment


Angular version: 5.0.0
Angular CLI: 1.5.0


For Tooling issues:
- Node version: 8.8.1
- Platform: Linux

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 26
  • Comments: 18 (2 by maintainers)

Most upvoted comments

import {HttpClientModule} from ‘@angular/common/http’; import {HttpModule} from ‘@angular/http’;

imports:[HttpClientModule, HttpModule providers:[HttpClientModule] If you use above things, it should solve the problem.

@ericmartinezr Thanks for the link. Importing both HttpModule and HttpClientModule fixes the problem. It’s caused by angular2-jwt because it still relies on the first one.

i meet this problem too, and i import HttpMoudle into my app.module.ts ,and the problem was gone.

i meet this problem too. For fixed him i just use :

import {HttpClientModule} from ‘@angular/common/http’; import {HttpModule} from ‘@angular/http’;

imports:[HttpClientModule, HttpModule]

don t need for add HttpClientModule in providers

Having similar issues with those imports.

Error: StaticInjectorError[ReportsService]: [INFO] StaticInjectorError[ReportsService]: [INFO] NullInjectorError: No provider for ReportsService! in http://localhost:9877/_karma_webpack_/vendor.bundle.js (line 85356)

Thanks @mahanjoy for your answer, but still not working for me…

As suggested by @zhaoshiming import HttpModule in app.module.ts. I also faced same issue, after importing HttpModule problem was fixed.

when i run the ionic lab command and this error are continuously produce so what can i do for that resolution please suggest me any one …!! core.js:1448 ERROR Error: Uncaught (in promise): Error: StaticInjectorError(AppModule)[LoginPage -> Headers]: StaticInjectorError(Platform: core)[LoginPage -> Headers]: NullInjectorError: No provider for Headers! Error: StaticInjectorError(AppModule)[LoginPage -> Headers]: StaticInjectorError(Platform: core)[LoginPage -> Headers]: NullInjectorError: No provider for Headers! at NullInjector.get (core.js:1002) at resolveToken (core.js:1300) at tryResolveToken (core.js:1242) at StaticInjector.get (core.js:1110) at resolveToken (core.js:1300) at tryResolveToken (core.js:1242) at StaticInjector.get (core.js:1110) at resolveNgModuleDep (core.js:10854) at NgModuleRef.get (core.js:12087) at resolveDep (core.js:12577) at NullInjector.get (core.js:1002) at resolveToken (core.js:1300) at tryResolveToken (core.js:1242) at StaticInjector.get (core.js:1110) at resolveToken (core.js:1300) at tryResolveToken (core.js:1242) at StaticInjector.get (core.js:1110) at resolveNgModuleDep (core.js:10854) at NgModuleRef.get (core.js:12087) at resolveDep (core.js:12577) at c (polyfills.js:3) at Object.reject (polyfills.js:3) at NavControllerBase._fireError (nav-controller-base.js:223) at NavControllerBase._failed (nav-controller-base.js:216) at nav-controller-base.js:263 at t.invoke (polyfills.js:3) at Object.onInvoke (core.js:4749) at t.invoke (polyfills.js:3) at r.run (polyfills.js:3) at polyfills.js:3

Is there a solution for this problem? I have set up everything according to different suggestions, including: importing HttpModule and HttpClientModule in app.module.ts and injecting the provider into the page.ts. The app is built correctly. But when making the get request I get this error:

ERROR Error: Uncaught (in promise): Error: StaticInjectorError[HttpAngularProvider]: StaticInjectorError[HttpAngularProvider]: NullInjectorError: No provider for HttpAngularProvider! Error: StaticInjectorError[HttpAngularProvider]: StaticInjectorError[HttpAngularProvider]: NullInjectorError: No provider for HttpAngularProvider! at _NullInjector.get (core.js:923) at resolveToken (core.js:1211) at tryResolveToken (core.js:1153) at StaticInjector.get (core.js:1024) at resolveToken (core.js:1211) at tryResolveToken (core.js:1153) at StaticInjector.get (core.js:1024) at resolveNgModuleDep (core.js:10584) at _createClass (core.js:10625) at _createProviderInstance$1 (core.js:10595) at _NullInjector.get (core.js:923) at resolveToken (core.js:1211) at tryResolveToken (core.js:1153) at StaticInjector.get (core.js:1024) at resolveToken (core.js:1211) at tryResolveToken (core.js:1153) at StaticInjector.get (core.js:1024) at resolveNgModuleDep (core.js:10584) at _createClass (core.js:10625) at _createProviderInstance$1 (core.js:10595) at c (polyfills.js:3) at c (polyfills.js:3) at polyfills.js:3 at t.invokeTask (polyfills.js:3) at Object.onInvokeTask (core.js:4617) at t.invokeTask (polyfills.js:3) at r.runTask (polyfills.js:3) at o (polyfills.js:3) at e.invokeTask [as invoke] (polyfills.js:3) at p (polyfills.js:2)

I would appreciate any help with this.

Im doing some Nativescript + Angualr 2 and ran into this issue too today. I cant recall why it stopped working, seemed to appear “out of nowhere”. But it was resolved when I took a look at the “Groceries” tutorial and added the NativeScriptHttpModule module:

app.module.ts

import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core";
import { NativeScriptModule } from "nativescript-angular/nativescript.module";
import { NativeScriptRouterModule } from "nativescript-angular/router";
import { AppComponent } from "./app.component";
import { LoginService } from "./shared/login/login.service";
import { routes, navigatableComponents } from "./app.routing";
// Uncomment and add to NgModule imports if you need to use two-way binding
import { NativeScriptFormsModule } from "nativescript-angular/forms";
// Uncomment and add to NgModule imports  if you need to use the HTTP wrapper
import { NativeScriptHttpModule } from "nativescript-angular/http"; // <--- HERE

@NgModule({
    bootstrap: [
        AppComponent
    ],
    imports: [
        NativeScriptModule,
        NativeScriptRouterModule,
        NativeScriptRouterModule.forRoot(routes),
        NativeScriptFormsModule,
        NativeScriptHttpModule // <--- HERE
    ],
    declarations: [
        AppComponent,
        ...navigatableComponents
    ]
    ,    providers: [ LoginService ]
})
/*
Pass your application module to the bootstrapModule function located in main.ts to start your app
*/
export class AppModule { }

@danger89 It’s not caused by Angular, but some of your 3-rd party libraries.