tomastrajan / angular-ngrx-material-starter

Angular, NgRx, Angular CLI & Angular Material Starter Project
https://tomastrajan.github.io/angular-ngrx-material-starter
MIT License
2.82k stars 919 forks source link

BrowserModule has already been loaded error when importing an angular library that imports BrowserModule #567

Closed jbistis closed 2 years ago

jbistis commented 2 years ago

I am trying to use a component from an angular library and get the console error:

BrowserModule has already been loaded. If you need access to common directives such as NgIf and NgFor from a lazy loaded module, import CommonModule instead.

Both the SharedModule from the library and the AppModule in the app have the imports import { BrowserModule } from '@angular/platform-browser'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

The library is imported into the AppModule using import { SharedModule as pdlSharedModule } from 'pdl';

If I remove the Browser imports from pdlSharedModule and try to use instead get the console error message NullInjectorError: R3InjectorError(t)[y -> y -> y -> y]: when I try to access

If I remove the Browser imports from AppModule that gets the same NullInjectorError but on the first page.

I am just not sure of the correct way to import an angular library with angular-ngrx-material-starter. I am on angular cli version 12.2.6

jbistis commented 2 years ago

Angular support has indicated this looks like an angular bug. https://github.com/angular/angular/issues/44015