Component is part of the declaration of 2 modules

前端 未结 16 724
我在风中等你
我在风中等你 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:18

    I had the same error but I discovered that when you import an AddEventModule, you can't import an AddEvent module as it would present an error in this case.

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

    Solved it -- Component is part of the declaration of 2 modules

    1. Remove pagename.module.ts file in app
    2. Remove import { IonicApp } from 'ionic-angular'; in pagename.ts file
    3. Remove @IonicPage() from pagename.ts file

    And Run the command ionic cordova build android --prod --release its Working in my app

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

    Solution is very simple. Find *.module.ts files and comment declarations. In your case find addevent.module.ts file and remove/comment one line below:

    @NgModule({
      declarations: [
        // AddEvent, <-- Comment or Remove This Line
      ],
      imports: [
        IonicPageModule.forChild(AddEvent),
      ],
    })
    

    This solution worked in ionic 3 for pages that generated by ionic-cli and works in both ionic serve and ionic cordova build android --prod --release commands!

    Be happy...

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

    Had same problem. Just make sure to remove every occurrence of module in "declarations" but AppModule.

    Worked for me.

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

    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

     this.navCtrl.push("Login"); // Bug
    

    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

    this.navCtrl.push(Login); // Correct

    I can't explain the difference at this time since i'm a beginner level developer

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

    Some people using Lazy loading are going to stumble across this page.

    Here is what I did to fix sharing a directive.

    1. create a new shared module

    shared.module.ts

    import { NgModule, Directive,OnInit, EventEmitter, Output, OnDestroy, Input,ElementRef,Renderer } from '@angular/core';
    import { CommonModule } from '@angular/common';
    
    import { SortDirective } from './sort-directive';
    
    @NgModule({
      imports: [
      ],
      declarations: [
      SortDirective
      ],
      exports: [
        SortDirective
      ]
    })
    
    export class SharedModule { }
    

    Then in app.module and your other module(s)

    import {SharedModule} from '../directives/shared.module'
    ...
    
    @NgModule({
       imports: [
           SharedModule
           ....
           ....
     ]
    })
    export class WhateverModule { }
    
    0 讨论(0)
提交回复
热议问题