aleksejjj
aleksejjj

Reputation: 1565

ERROR in No NgModule metadata found for 'HomeModule'

I am getting the error mentioned in the title when running the Ionic CLI command ionic cordova run android.

What I tried to fix the problem:

Checked that main.ts file contains the following code

platformBrowserDynamic().bootstrapModule(AppModule)
  .catch(err => console.log(err));

Removed node_modules folder and ran npm install.

Reinstalle angular/cli with the commands posted in this answer.

app.module.ts:

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } 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 { HttpClientModule } from '@angular/common/http';
import { SijaintiService } from '../app/sijainti.service';
import { RouterModule, Routes } from '@angular/router';

@NgModule({
  declarations: [AppComponent],
  entryComponents: [],
  imports: [
    BrowserModule, 
    IonicModule.forRoot(), 
    AppRoutingModule, 
    HttpClientModule,
    RouterModule.forRoot([
      { path: '', redirectTo: '/home', pathMatch: 'full' },
      { path: 'home', loadChildren: './home/home.module#HomeModule' },
      { path: 'tiedot', loadChildren: './tiedot/tiedot.module#TiedotModule' }
    ])
  ],
  providers: [
    StatusBar,
    SplashScreen,
    { provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
    SijaintiService
  ],
  bootstrap: [AppComponent]
})
export class AppModule {}

home.module.ts:

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 {}

Upvotes: 1

Views: 1182

Answers (2)

Dhananjai Pai
Dhananjai Pai

Reputation: 6015

You are naming the module as HomePageModule and the error is HomeModule not defined. Could be a typo ?

You could either rename the export as

export class HomeModule {}

or modify the lazy loaded module as

{ path: 'home', loadChildren: './home/home.module#HomePageModule' }, // from HomeModule

Upvotes: 1

Rathnakara S
Rathnakara S

Reputation: 1466

Change HomeModule to HomePageModule in your route list, because your class name is HomePageModule.

Change this,

 { path: 'home', loadChildren: './home/home.module#HomeModule' },

to this,

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

Upvotes: 3

Related Questions