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.

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

See original GitHub issue

Which @angular/* package(s) are the source of the bug?

platform-browser

Is this a regression?

No

Description

I am trying to use a component from an angular library (SharedModule) 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 SharedModule and try to use CommonModule instead, I 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.

user.module.ts.txt app.module.ts.txt shared.module.ts.txt

This configuration worked in a9.

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

ERROR Error: Uncaught (in promise): 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.
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.
    at new qe (main.js:1)
    at Object.qe.ɵfac [as factory] (main.js:1)
    at I3.hydrate (main.js:1)
    at I3.get (main.js:1)
    at main.js:1
    at Set.forEach (<anonymous>)
    at I3._resolveInjectorDefTypes (main.js:1)
    at new Wg (main.js:1)
    at If.create (main.js:1)
    at i.project (main.js:1)
    at A (polyfills.js:1)
    at A (polyfills.js:1)
    at polyfills.js:1
    at h.invokeTask (polyfills.js:1)
    at Object.onInvokeTask (main.js:1)
    at h.invokeTask (polyfills.js:1)
    at h.runTask (polyfills.js:1)
    at m (polyfills.js:1)
    at h.invokeTask [as invoke] (polyfills.js:1)
    at y (polyfills.js:1)

Please provide the environment you discovered this bug in

Angular CLI: 12.2.6
Node: 12.19.0
Package Manager: npm 6.14.8
OS: darwin x64

Angular: 12.2.6
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Anything else?

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jbistiscommented, Nov 3, 2021

We are working on a small reproduction of the issue.

0reactions
angular-automatic-lock-bot[bot]commented, Jan 11, 2022

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Lazy Loading BrowserModule has already been loaded
This error can occur if you have imported BrowseModule in some child.app module.ts also. Please make sure ...
Read more >
Angular build showing BrowserModule has already been ...
Re: Angular build showing BrowserModule has already been loaded on browser ... @tbsouza: Please remove the import for the BrowserModule from any ...
Read more >
Import once Browser Module - DEV Community ‍ ‍
This error is self explanatory and tells us that BrowserModule has already been loaded and it does not need to be loaded again....
Read more >
Lazy Loading in Angular2 Error: BrowserModule has already ...
Solution: As error description is self explanatory, the module for which you want to implement lazy loading shouldn't import BrowserModule as ...
Read more >
version 7.5.0 : BrowserModule has already been loaded
ERROR Error : Uncaught (in promise): Error: BrowserModule has already been ... As a workaround you can import only specific modules you need...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

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