0
votes

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 {}
2
PS. MY HOME FOLDER THERE'S ALSO A MODULE:import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { IonicModule } from '@ionic/angular'; import { FormsModule } from '@angular/forms'; import { RouterModule } from '@angular/router'; import { HomePage } from './home.page'; @NgModule({ imports: [ CommonModule, FormsModule, IonicModule, RouterModule.forChild([ { path: '', component: HomePage } ]) ], declarations: [HomePage] }) export class HomePageModule {}Bruno Silva
is there another module called homepage moduleSathiraumesh
yes there is and its inside the home folder(home component)Bruno Silva
ok do you want to use lazy load or do you just want to use itSathiraumesh
if you just want to use it remove declarations:[homepage] from HomepageModule it should do fine as y0u have declared it in the appmodulesSathiraumesh

2 Answers

0
votes

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'
 },
0
votes

You could do the following Remove the declarations: [HomePage] from the Homepage Module. if you are not lazy loading

or

you could Either keep it there in the homepage module and remove Homepage it from app modules declarations: [AppComponent,HomePage], if you are lazy loading

or if you want to just modularize it you could Either keep it there in the homepage module and remove Homepage it from app modules declarations: [AppComponent,HomePage],and add it to exports:[HomePage] in home page Module and import The homepage module to appmodule`

imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule,RouterModule],HomePageModule,...