2

I'm pretty new on Angula2 and Ionic world, so, I'm currently developing a tabs app with various pages, components and providers. It works fine when i run ionic serve command. Now I'm trying to generate the APK and I get that error. In my app.module.ts i have declarations like that :

@NgModule({declarations: [
    MyApp,
    MenuPage,
    OrdersPage,
    DatiPage,
    ....
TextImg]

and also, every page has it's own page.module.ts file containing something like :

import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { DatiPage } from './dati';

@NgModule({declarations: [
    DatiPage,
  ],imports: [
  IonicPageModule.forChild(DatiPage),
 ],
})
export class DatiPageModule {}

If i remove one of the two declarations, ionic serve webapp stops working. Otherway, if I try to build apk, i get this :

enter image description here

Sorry long paths, but that's it. Do someone know what I'm doing wrong? Thank you!

sebaferreras
  • 44,206
  • 11
  • 116
  • 134
user1840039
  • 135
  • 3
  • 12
  • I've added the answer before knowing it was a duplicate question. Thanks **[Duannx](https://stackoverflow.com/users/4254681/duannx)** for pointing that out. – sebaferreras Sep 23 '17 at 06:37

1 Answers1

3

every page has its own page.module.ts file containing something like [...]

Seems like you're using lazy-loaded pages. Since each page is loaded only when needed, you need to remove these pages from the app.module.ts file

@NgModule({
    declarations: [
      MyApp,
      // MenuPage, // <---- Remove the pages from the app module
      // OrdersPage,
      // DatiPage,
      ....
      TextImg
    ]
    //...
  })
  export class AppModule { }

Now each page should be declared only in its own module (this should remove the type ... is part of the declarations of two modules error)

And since these pages are being lazy-loaded, when you need to navigate to any of these pages, you need to use a string with its name and not the component name:

// When setting the page in the app.component.ts page
rootPage:any = 'HomePage';

Please also notice that since it's a string, you don't need to import the HomePage in any file.

You can find more information about lazy-loading in these two blog posts from Ionic's blog:

sebaferreras
  • 44,206
  • 11
  • 116
  • 134
  • Thank you for your answer sebaferreras, I did like you said but still it's not working. I gave a look at the first question of which mine is a duplicate and I don't get something. @snorkpete says to remove AddEvent from declarations and imports, and import "AddEventModule" instead, adding then "AddEventModule" on imports, but he also has a "AddEvent" declared on entryComponents.. Is that a refuse? Or the "AddEvent" has to be in entryComponents? I suppose no, because no "AddEvent" is on top imports – user1840039 Sep 25 '17 at 12:38