BrowserModule has already been loaded Error

后端 未结 10 2252
猫巷女王i
猫巷女王i 2020-12-08 18:56

I\'ve updated my application to RC6 and now i keep getting this error:

zone.js:484 Unhandled Promise rejection: BrowserModule has already been loade

10条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-08 19:26

    As the error description is self-explanatory, the module for which you want to implement lazy loading shouldn’t import BrowserModule as this is already been imported earlier (mainly in app.component). You should only import BrowserModule once. Other modules should be importing CommonModules instead.

    See the code below for understanding

    import { NgModule } from '@angular/core';
    import { CommonModule } from '@angular/common'; //<-- This one 
    
    import { SearchMovieMainComponent } from './search-movies-main.component';
    
    @NgModule({
        imports: [
            CommonModule //<-- and this one 
        ],
        declarations: [
            SearchMovieMainComponent
        ]
    })
    export class SearchMoviesMainModule {
    }
    

    Note: This is not my own answer. I was facing the same problem. Where I myself have a CommonModule in the same name of angular one. So it was real a problem for me, as I was not aware that there is another CommonModule that exists in angular itself. I found this blog helpful. Posting the answer from there.

提交回复
热议问题