Intento construir una aplicación iónica 2. Cuando pruebo la aplicación en el navegador con servicio iónico o la ejecuto en un emulador, todo funciona bien.
Pero cuando trato de construirlo cada vez que aparece el 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 create a new NgModule that exports and includes AddEvent then import that NgModule in AppModule and AddEventModulemi AppModule es
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 {}y mi add-event.module.ts es
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 {}Entiendo que tengo que eliminar una de las declaraciones, pero no sé cómo.
Si elimino la declaración de AppModule, aparece un error que indica que no se encuentra la página de inicio de sesión mientras se ejecuta el servicio iónico.
Quite la declaración de AppModule , pero actualice la configuración de AppModule para importar su 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 {}También,
Tenga en cuenta que es importante que AddEventModule exporte el componente AddEvent si desea usarlo fuera de ese módulo. Afortunadamente, ya lo tiene configurado, pero si se omitiera, habría recibido un error si intentara usar el componente AddEvent en otro componente de su AppModule
Algunas personas que usan Lazy loading se encontrarán con esta página.
Esto es lo que hice para solucionar el problema de compartir una directiva .
módulo.compartido.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 { }Luego en app.module y sus otros módulos
import {SharedModule} from '../directives/shared.module' ... @NgModule({ imports: [ SharedModule .... .... ] }) export class WhateverModule { }La solución es muy simple. Encuentre archivos *.module.ts y declaraciones de comentarios. En su caso, busque el archivo addevent.module.ts y elimine/comente una línea a continuación:
@NgModule({ declarations: [ // AddEvent, <-- Comment or Remove This Line ], imports: [ IonicPageModule.forChild(AddEvent), ], }) ¡Esta solución funcionó en ionic 3 para páginas generadas por ionic-cli y funciona tanto en ionic serve como en ionic cordova build android --prod --release commands!
Ser feliz...