I try to build an ionic 2 app. When I try the app in the browser with ionic serve or launch it on an emulator everything works fine.
But when I try to build it every time the error
ionic-app-script tast: "build"
Error Type AddEvent in "PATH"/add.event.ts is part of the declarations of 2 modules: AppModule in "PATH"/app.modules.ts and AddEvent in "PATH"/add-event.module.ts.
Please consider moving AddEvent in "PATH"/add-event.ts to a higher module that imports AppModule in "PATH"/app.module.ts and AddEventModule.
You can also creat a new NgModule that exports and includes AddEvent then import that NgModule in AppModule and AddEventModule
my AppModule is
import { NgModule, ErrorHandler } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
import { AngularFireModule } from 'angularfire2';
import { MyApp } from './app.component';
import { Eventdata } from '../providers/eventdata';
import { AuthProvider } from '../providers/auth-provider';
import { HttpModule } from '@angular/http';
import { HomePage } from '../pages/home/home';
import { Login } from '../pages/login/login';
import { Register } from '../pages/register/register';
import { AddEvent } from '../pages/add-event/add-event';
import { EventDetails } from '../pages/event-details/event-details';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
@NgModule({
declarations: [
MyApp,
HomePage,
Login,
Register,
AddEvent,
EventDetails
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp),
HttpModule,
AngularFireModule.initializeApp(config)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage,
Login,
Register,
AddEvent,
EventDetails
],
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler}, Eventdata, AuthProvider
]
})
export class AppModule {}
and my add-event.module.ts is
import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { AddEvent } from './add-event';
@NgModule({
declarations: [
AddEvent,
],
imports: [
IonicPageModule.forChild(AddEvent),
],
exports: [
AddEvent
]
})
export class AddEventModule {}
I understand that I have to remove one of the declarations, but I dont know how.
If I remove the declaration from AppModule I get an Error that the Login Page is not found, while running ionic serve
IN Angular 4. This error is considered as ng serve run time cache issue.
case:1 this error will occur, once you import the component in one module and again import in sub modules will occur.
case:2 Import one Component in wrong place and removed and replaced in Correct module, That time it consider as ng serve cache issue. Need to Stop the project and start -do again ng serve, It will work as expected.
As the error says to remove the module AddEvent from root if your Page/Component is already had ionic module file if not just remove it from the other/child page/component, at the end page/component should be present in only one module file imported if to be used.
Specifically, you should add in root module if required in multiple pages and if in specific pages keep it in only one page.
Simple fix,
Go to your
app.module.ts
file andremove/comment
everything that binds withadd_event
. There is no need of adding components to theApp.module.t
s which are generated by theionic cli
because it creates a separate module for components calledcomponents.module.ts
.It has the needed module component imports
This module is added automatically when you run ionic command. However it's not necessery. So an alternative solution is to remove add-event.module.ts from the project.
You may just try this solution ( for Ionic 3 )
In my case, this error happen when i call a page by using the following code
I just removed the quotes like the following and also imported that page on the top of the file which i used call the Login page
I can't explain the difference at this time since i'm a beginner level developer
Had same problem. Just make remove every occurrence of module in "declarations" but AppModule.
Worked for me.