I am trying to implement lazy loading but getting error as following **
ERROR Error: Uncaught (in promise): Error: BrowserModule has already been loaded.
Include all the common modules in parent component only(or appModule only). In child module, include only Child specific modules.
Also, you might need to add
schemas: [NO_ERRORS_SCHEMA],
in your child modules and parent modules
In my case I had shared module which was importing BrowserAnimationModule. I was importing shared module in my root module. to solve this error remove all imports of BrowserAnimationModule from all modules and add it to root module.
imports: [
AppRoutingModule,
SharedModule,
BrowserAnimationsModule
],
This error can occur if you have imported BrowseModule in some child.app module.ts also. Please make sure you import CommonModule in all modules other than app.module as it has browser modules.
I also got the same error and finally, after little bit struggle, I was able to fix it.
Import these mentioned modules only once(in app-module only):
BrowserModule, BrowserAnimationsModule, LazyLoadImageModule (if using it), CarouselModule (if using it), InfiniteScrollModule (if using it), HttpModule ( if using it)
I had the same problem and Jota.Toledo gave the correct answer and I want only extend that: please check in shared module imports any modules that related with
@angular/platform-browser/animations
and move those modules into app.module.ts
@First Import BrowerModule and in imports also first include BrowserModule import:[BrowerModule ]
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AppRoutingModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
If we declare BrowserModule
in any module other than app module(Duplicate)
this error will come. the In app module if we import 10 modules or plugins, first we have to import BrowserModule
at the top and declare in decorates (import:[BrowserModule ])
at the top