question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ERROR : "NullInjectorError: No provider for NgZone!" when import a library.

See original GitHub issue

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Command (mark with an x)

- [ ] new
- [ ] build
- [ ] serve
- [ ] test
- [ ] e2e
- [x] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Versions

node v10.8.0 npm 6.2.0 os win10 angular 6.1.2

Repro steps

1.run commands: ng new mylib-demo, cd mylib-demo, ng generate library mylib 2.cd projects/mylib/src/lib ,edit mylib.module.ts, imports BrowserModule. 3.cd …/…/…/…/, ng build mylib, npm link dist/mylib 4.ng new test-mylib, npm link mylib, edit app.module.ts, imports MylibModule. ng serve -o, then browser console show the error: NullInjectorError: No provider for NgZone!

there is a same issue:

The log given by the failure

1.compiled error: WARNING in …/mylib-demo/node_modules/@angular/core/fesm5/core.js 4996:15-36 Critical dependency: the request of a dependency is an expression

WARNING in …/mylib-demo/node_modules/@angular/core/fesm5/core.js 5008:15-102 Critical dependency: the request of a dependency is an expression i 「wdm」: Compiled with warnings.

2.the browser console error: Error: StaticInjectorError(AppModule)[ApplicationRef -> NgZone]: StaticInjectorError(Platform: core)[ApplicationRef -> NgZone]: NullInjectorError: No provider for NgZone! at NullInjector.push…/node_modules/@angular/core/fesm5/core.js.NullInjector.get (core.js:1062) at resolveToken (core.js:1300) at tryResolveToken (core.js:1244) at StaticInjector.push…/node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js:1141) at resolveToken (core.js:1300) at tryResolveToken (core.js:1244) at StaticInjector.push…/node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js:1141) at resolveNgModuleDep (core.js:8376) at _createClass (core.js:8429) at _createProviderInstance (core.js:8393)

Desired functionality

Mention any other details that might be useful

1.mylib demo: mylib.module.ts import { NgModule } from '@angular/core'; import { MylibComponent } from './mylib.component'; import {BrowserModule} from '@angular/platform-browser'; @NgModule({ imports: [ BrowserModule ], declarations: [MylibComponent], exports: [MylibComponent] }) export class MylibModule { } 2.test-mylib: app.module.ts import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; import {MylibModule} from 'mylib'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, MylibModule ], providers: [], bootstrap: [AppComponent] }) export class AppModule { }

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:18 (1 by maintainers)

github_iconTop GitHub Comments

13reactions
charlee2025commented, Aug 14, 2018

@alan-agius4 ,YES, it works. But it will be ./node_modules/@angular/* not ../ Thank you very mach. When you come to china, I would like to invite you to dinner.

6reactions
alan-agius4commented, Aug 14, 2018

BrowserModule shouldn’t be used in a library. Use CommonModule intead.

BrowserModule is intended to be used only at an application level and imported in the root module.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NullInjectorError: No provider for NgZone! (Angular 6 library)
But the problem is with importing the BrowserModule . Do not import it into your library module and it should work.
Read more >
NullInjectorError: No provider for NgZone! (Angular 6 library)
I created an Angular 6 library, but I get an error when I try to use it outside of the project in which...
Read more >
angular/angular - Gitter
hi all, I have a angular project that depend to my library .i want using yarn link in ... NgZone]: NullInjectorError: No provider...
Read more >
NG0201: No provider for {token} found! - Angular
You see this error when you try to inject a service but have not declared a corresponding provider. A provider is a mapping...
Read more >
I have run npm link from within the dist directory and ... - Medium
Error : StaticInjectorError[NgZone]: StaticInjectorError[NgZone]: NullInjectorError: No provider for NgZone! One of thecomponents uses the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found