NullInjectorError: No provider for NgZone! (Angular 6 library)

*爱你&永不变心* 提交于 2019-12-03 16:16:43

Well, I don't know why. But the problem is with importing the BrowserModule. Do not import it into your library module and it should work.

import { NgModule } from '@angular/core';
import { ExampleComponent } from './example.component';
//import { BrowserModule } from '@angular/platform-browser'; // added

@NgModule({
  imports: [
   // BrowserModule // removed
  ],
  declarations: [ExampleComponent],
  exports: [ExampleComponent]
})
export class ExampleModule { }

I have been in this for a very long time and removed the imports in my library module one by one. It was the BrowserModule.

I think this should answer your other question.

Have you tried to add the following in your tsconfig.json file:

"paths": {
      "@angular/*": [
        "./node_modules/@angular/*"
      ]
    },

Please note the path is ./node_modules, some suggest ../node_modules, the latter did not work for me.

Hope this will help someone. It took me a very long time to get to the solution. Thanks to: https://github.com/angular/angular-cli/issues/11883

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!