angular: Angular 5.0.0 error: StaticInjectorError[InjectionToken DocumentToken]
I’m submitting a…
[x] Regression (a behavior that used to work and stopped working in a new release)
[ ] 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
I have upgraded my current project from 4.4.4 to 5.0.0 using the recommandations from https://angular-update-guide.firebaseapp.com/
And now when I launch ng serve
, the page keeps blank and the browser console returns the following error:
zone.js:391 Uncaught (in promise) Error: StaticInjectorError[InjectionToken DocumentToken]:
StaticInjectorError[InjectionToken DocumentToken]:
NullInjectorError: No provider for InjectionToken DocumentToken!
The traceback indicates it comes from the bootstraping in my main.ts
:
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.log(err));
but unfortunately, nothing more specific.
Expected behavior
No error.
Minimal reproduction of the problem with instructions
I do not know how to reproduce this bug, my existing codebase is quite large.
I am aware it might be difficult to answer my issue, but I just ask to know if this error message rings a bell to anyone, so I know where to start digging.
What is the motivation / use case for changing the behavior?
Environment
Angular CLI: 1.5.0
Node: 8.7.0
OS: darwin x64
Angular: 5.0.0
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
@angular/cdk: 2.0.0-beta.8
@angular/cli: 1.5.0
@angular/flex-layout: 2.0.0-beta.9
@angular/material: 2.0.0-beta.8
@angular-devkit/build-optimizer: 0.0.32
@angular-devkit/core: 0.0.20
@angular-devkit/schematics: 0.0.35
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.8.0
@schematics/angular: 0.1.0
typescript: 2.4.2
webpack-bundle-analyzer: 2.9.0
webpack: 3.8.1
Browser:
- Chrome (desktop) version XX
- Chrome (Android) version XX
- Chrome (iOS) version 62.0.3202.62
- Firefox version XX
- Safari (desktop) version XX
- Safari (iOS) version XX
- IE version XX
- Edge version XX
For Tooling issues:
- Node version: XX <!-- run
node --version
--> - Platform:
Others:
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 14
- Comments: 55 (3 by maintainers)
Commits related to this issue
- added HttpClientModule, see https://github.com/angular/angular/issues/20101 — committed to znegva/ionic-sidemenu-issue by znegva 7 years ago
- Re-add HttpModule https://github.com/angular/angular/issues/20101 — committed to cvisb/cvisb_data by flaneuse 5 years ago
No need to import HttpModule import {HttpModule} from ‘@angular/http’ – Not Required
Just make sure, you have provided your service in providers after importing it in app.module.ts Like -
import { ApiService } from ‘./app.service’ imports: [ BrowserModule, ], providers: [ApiService],
I think this error occurs because you need to import HttpModule(deprecated) as well as HttpClientModule, because some dependency still relies on HttpModule.
import {HttpClientModule, HttpClient} from ‘@angular/common/http’;
then: imports:[ HttpClientModule]
will be ok
Add this in app.module.ts
import { HttpClientModule } from ‘@angular/common/http’
and also add HttpClientModule in your imports
@Sagar1990 have you imported this
import { HttpClientModule } from ‘@angular/common/http’
in app.module.ts?
Yes adding these below to app.module.ts worked. Thanks @usmanakram1996
import { HttpModule } from ‘@angular/http’;
and importing worked
imports: [ HttpModule ]
@ochezeau You’ll need
--preserve-symlinks
in (app’s) build when (lib) link to a different repo. That’s what happened in #20102.Same error, but only works on some components and routes, any solution?
Stuck here The xxxx xxxxx this xxx … Help out guys with exact matching solution all solutions are xxxxx… NEED PROPER HELP ERROR Error: StaticInjectorError(AppModule)[AppComponent -> AngularFireDatabase]: StaticInjectorError(Platform: core)[AppComponent -> AngularFireDatabase]: NullInjectorError: No provider for AngularFireDatabase! 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)
Please reply or comment Only If You Know where this makes shit…
I solve this by following two steps:
Not working with any of the solutions above
Attached are the files—
I fixed my problem. For me, everything was working well with a : build --prod I had the problem using a common library (unsing an npm link) and with the command ng build --watch (I use a tomcat server) I fixed the problem using the command: npm build --aot --watch (adding --aot) Is is alos important to have the right version of components : angular-cli : 1.5 and typescript 2.4.2
I got this error after importing a component library I built with ng-packagr. I had to change the
dependencies
parameter topeerDependencies
in thepackage.json
of my component library as outlined here. This cost me days to root out.I am getting the same error, including Httpmodule did not work for me.
my app.module.ts: -
exportTopdf.component.ts file: -
my service code: -
system.config.js: -
package.json: -
Error i am getting is: -
Is this a troll post XD Go SO wtf
All you need to do is to import your service in your app.module, like,
import { HeroService } from ‘…/app/hero.service’;
and then, provide it to your providers array in the same file, like,
providers: [HeroService]
I hope this will help…
Hey, I’m struggling with similar issue as this stackOverFlow question - Angular can’t use HttpClient in external library. In short - i’m trying to compile my app as a ng-module (using ngc), so it could be imported by another outer app. Unfortunately, though my app works fine by itself; it can’t be imported by the outer app, due to the error mentioned above. None of the solutions suggested above solved the problem. Help would be appreciated.
In my case, a
Route guard
was not added to theproviders: any[]
inside of@ngModule
;I was like, HAY HOERAY let’s start a new project (templated from Visual Studio 2017 v15.7.3) didn’t even run out of the box but I want to upgrade angular anyway to 6, did that, solved every dependency issue that was raised until no warnings were left. Boom, got this, no issue seems to resolve my issue. Ended up copy-pasting an other web project with angular 5.0.1 which works.
Angular Team, I call this unstable release management.
I already had these import statements inside my app.module.But still the StaticInjectorError …NullInjectorError poped up.
import { BrowserModule } from ‘@angular/platform-browser’; import { BrowserAnimationsModule } from ‘@angular/platform-browser/animations’; import { HttpClientModule } from ‘@angular/common/http’;
THIS IS HOW I GOT IT RESOLVED The error happened because I forgot to import my service into app.module.ts file.
import {xyzNotificationService } from './services/eventoccurrences.service';
and then add your service for eg., xyzNotificationService__ to the providers: [ ] section of your app.module
I have the same problem with Angular 5.2.7 When i try to add :
In my component, this generates an error :
I have try all solution exposed in above but no works…
@kverma17 You only need to change your
dependencies
topeerDependencies
if you are building a library. You might try updating all angular dependencies to latest, I know better error definitions for this error were a part of 5.2 or 5.1. I am guessing some library you are dependent on changed their syntax without documenting it as happened to en-sevilla. Firebase hase been bad about making these kinds of changes lately, I see you importing firebase in your app module but I don’t see it in yourpackage.json
. If you are using"firebase": "4.8.1"
roll it back to 4.8.0 as they made breaking changes to the way the modules are imported in 4.8.1.