Sign Up

Sign In

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Sorry, you do not have a permission to ask a question, You must login to ask question.

Component is part of the declaration of 2 modules

  • 0

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

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


Share

1 Answer

  1. 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

    • 0

Sorry, you do not have a permission to answer to this question.

close