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
Remove the declaration from AppModule
, but update the AppModule
configuration to import your AddEventModule
.
.....
import { AddEventModule } from './add-event.module'; // <-- don't forget to import the AddEventModule class
@NgModule({
declarations: [
MyApp,
HomePage,
Login,
Register,
//AddEvent, <--- remove this
EventDetails
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp),
HttpModule,
AngularFireModule.initializeApp(config),
AddEventModule, // <--- add this import here
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage,
Login,
Register,
AddEvent,
EventDetails
],
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler}, Eventdata, AuthProvider
]
})
export class AppModule {}
Also,
Note that it's important that your AddEventModule
exports the AddEvent
component if you want to use it outside that module. Luckily, you already have that configured, but if it was omitted, you would've gotten an error if you tried to use the AddEvent
component in another component of your AppModule
I accidentally created my own component with the same name as a library's component.
When I used my IDE to auto-import the library for the component, I chose the wrong library.
Therefore this error was complaining, that I was re-declaring the component.
I fixed by importing from my own component's code, instead of the library.
I could also fix by naming differently: avoid ambiguity.
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.
Simple fix,
Go to your app.module.ts
file and remove/comment
everything that binds with add_event
. There is no need of adding components to the App.module.t
s which are generated by the ionic cli
because it creates a separate module for components called components.module.ts
.
It has the needed module component imports