Ionic build --prod error: Type ... in ... is part of the declarations of 2 modules:

I am received a error when i use build --prod
image

Error

I already try import ChatItemModule and remove ChatItem of declarations, but the new error occour:

someone know shomething about this ?

1 Like

A post was split to a new topic: Error encountered resolving symbol values statically

did you have item.module.ts file?

You cannot declare any component in more than one single ngModule.

The solution for your first error is as follows:
Declare the ā€˜ChatItemā€™ component in either AppModule or ChatItemModule, but not in both of them.

1 Like

I had same error - remove ChatModule from @NgModules - declarations. Keep only in imports.

4 Likes

I run into the same issue, and I resolved itā€¦

But keep in mind that in order to create my Component, I run from command-line:

ionic g component MyComponent

So the command-line generator probably does do the job correctly, and misleading the developer.
Is this a bug?

Regards
Costas

What did you do additionally to ionic g component?
If nothing, then this is definitely a bug that should be reported at https://github.com/ionic-team/ionic-cli/issues

Yes but when you run ionic serve the following error appear:

Component is not part of any NgModule or the module has not been imported into your module. ; Zone: <root> ; Task: Promise.then ; Value: Error: Component ContratistasLista is not part of any NgModule or the module has not been imported into your module.
1 Like
  1. Delete ChatItem.Module.ts from the ChatItem folder
  2. In ChatItem.ts remove IonicPage

I think this should solve your problem.

I solved my from this!

12 Likes

infolder ChatItem
1.delete chatitem.module.ts
2.in chatitem.ts delete import{ Ionicpage } from ā€˜ionic-angularā€™;
3.in chatitem.ts delete @Ionicpage()
4.in terminal >ionic cordova build android --prod OR ionic cordova build ios --prod

21 Likes

Thanks @monoko26333 and @arnoldparge
This solve the issue!!!

2 Likes

This made the trick!

1 Like

I think we should do in ionic way / angular for Page instead deleting, you could do this:

  1. in some.module, add exports and entryComponents

@NgModule({
declarations: [SomePage],
imports: [IonicPageModule.forChild(SomePage)],
exports: [SomePage],
entryComponents: [SomePage]
})

  1. edit app.module, now we only need to import module, no need to add declarations or entryComponents

@NgModule({
imports: [
ā€¦
SomePageModule,
ā€¦

Donā€™t know why ionic-cli not added this when generate page.
Sadly, whenever generating page, iā€™m always redo this :sweat:

2 Likes

This is how i fixed it:

  1. Remove all pages from imports: [ ... ] in app.module.ts.
  2. Remove all pages from entryComponents: [..] in app.module.ts.
    NOTE: Do not delete the generated mypage.module.ts files.**
  3. Add the generated module files to imports: [ ... ] in app.module.ts.

Hereā€™s a full example of my app.module.ts:

import { NgModule, ErrorHandler } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
import { HttpModule } from '@angular/http';
import { IonicStorageModule } from '@ionic/storage';
import { MyApp } from './app.component';

import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { PlanProvider } from '../providers/plan/plan';
import { ExerciseProvider } from '../providers/exercise/exercise';
import { TabsPageModule } from '../pages/tabs/tabs.module';
import { TrainingPageModule } from '../pages/training/training.module';
import { PlansPageModule } from '../pages/plans/plans.module';
import { CloudPageModule } from '../pages/cloud/cloud.module';
import { CreatePlanPageModule } from '../pages/create-plan/create-plan.module';

@NgModule({
  declarations: [
    MyApp
  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp),
    IonicStorageModule.forRoot(),
    HttpModule,
    TabsPageModule,
    TrainingPageModule,
    PlansPageModule,
    CloudPageModule,
    CreatePlanPageModule
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp
  ],
  providers: [
    StatusBar,
    SplashScreen,
    {provide: ErrorHandler, useClass: IonicErrorHandler},
    IonicStorageModule,
    PlanProvider,
    ExerciseProvider
  ]
})
export class AppModule {}
5 Likes

Generate a page creates a module for lazy-loaded pages in ionic3
If you donā€™t want to take advantage of lazy loading use
$ ionic generate [type] [name] --no-module // Do not generate an NgModule for the component

2 Likes

As far as I know @altergothen is right. The page-name.module.ts file and @IonicPage decorator are used for lazy loading and if you want to take advantage of it you should keep both of them.

You can learn more about Lazy Loading with Ionic in this article from the official blog - https://blog.ionicframework.com/ionic-and-lazy-loading-pt-1/

I think the point of Lazy Loading is not to declare these pages in app.module.ts in any form. They will be loaded on demand the first time you need them. You have to change all occurrences of the page to strings and Ionic will handle the rest. In the blog post mentioned above there are links to example projects where you can see how it should be.

YES, Si eliminado loe Module.ts and eliminado @IonicPage() ā€¦ Todo OK

Thanks, It works now.
But why the cli create this component.module.ts if we have to delete it in order to build without error ?

Thank you!!! This worked for me and it saved me a lot of time!!!

Dear Friends,
Donā€™t avoid lazy loading its an advanced feature of ionic 3 to make the performance better .
In Your app.module.ts you do only two editing for a page
Suppose your new page module is ā€˜BuidingStatusPageModuleā€™

then
import same as normal

import { BuildingStatusPageModule } from ā€œā€¦/pages/building-status/building-status.moduleā€;

then add

imports: [
   BuildingStatusPageModule,

Done . Your problem will solveā€¦

Try it and enjoy.

Thanks

Anes

2 Likes