Search code examples
angularangular7angular-module

declarations of 2 modules error in angular7


I'm trying to run my project, there is just one component, I added home to app.module but its ginvg me this error

Error: Uncaught (in promise): Error: Type HomePage is part of the declarations of 2 modules: AppModule and HomePageModule! Please consider moving HomePage to a higher module that imports AppModule and HomePageModule. You can also create a new NgModule that exports and includes HomePage then import that NgModule in AppModule and HomePageModule. Error: Type HomePage is part of the declarations of 2 modules: AppModule and HomePageModule! Please consider moving HomePage to a higher module that imports AppModule and HomePageModule. You can also create a new NgModule that exports and includes HomePage then import that NgModule in AppModule and HomePageModule. here's my app.module


import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouterModule, RouteReuseStrategy, Routes } from '@angular/router';

import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';

import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import { HomePage} from './home/home.page';

@NgModule({
  declarations: [AppComponent,HomePage],
  entryComponents: [],
  imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule,RouterModule],
  providers: [
    StatusBar,
    SplashScreen,
    { provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
  ],
  bootstrap: [AppComponent]
})
export class AppModule {}

Solution

  • You should remove HomePage from declarations

    change to declarations: [AppComponent], in AppModule

    If you want to use HomePage in route you can configure

    {    
          path: 'homepage',
          loadChildren: './homepage/homepage.module#HomePageModule'
     },