Component is part of the declaration of 2 modules

前端 未结 16 723
我在风中等你
我在风中等你 2020-12-04 06:44

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

相关标签:
16条回答
  • 2020-12-04 07:32

    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 讨论(0)
  • 2020-12-04 07:33

    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.

    0 讨论(0)
  • 2020-12-04 07:35

    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.

    0 讨论(0)
  • 2020-12-04 07:40

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

    0 讨论(0)
提交回复
热议问题