gpt4 book ai didi

angular - 页面是 2 个模块 : Error in ionic build prod 声明的一部分

转载 作者:太空狗 更新时间:2023-10-29 18:04:38 25 4
gpt4 key购买 nike

当我运行 npm run ionic:build 时,我能够成功构建。但是当我运行 npm run ionic:build --prod 时,我收到以下错误消息。

Error: Type PatientDetailPage in /home/shiva/Ionic/af2-lists/src/pages/patient-detail/patient-detail.ts is 
part of the declarations of 2 modules: AppModule in /home/shiva/Ionic/af2-lists/src/app/app.module.ts and
PatientDetailPageModule in /home/shiva/Ionic/af2-lists/src/pages/patient-detail/patient-detail.module.ts!
Please consider moving PatientDetailPage in
/home/shiva/Ionic/af2-lists/src/pages/patient-detail/patient-detail.ts to a higher module that imports
AppModule in /home/shiva/Ionic/af2-lists/src/app/app.module.ts and PatientDetailPageModule in
/home/shiva/Ionic/af2-lists/src/pages/patient-detail/patient-detail.module.ts. You can also create a new
NgModule that exports and includes PatientDetailPage in
/home/shiva/Ionic/af2-lists/src/pages/patient-detail/patient-detail.ts then import that NgModule in
AppModule in /home/shiva/Ionic/af2-lists/src/app/app.module.ts and PatientDetailPageModule in
/home/shiva/Ionic/af2-lists/src/pages/patient-detail/patient-detail.module.ts.
Error: Type PatientDetailPage in /home/shiva/Ionic/af2-lists/src/pages/patient-detail/patient-detail.ts is part of the declarations of 2 modules: AppModule in /home/shiva/Ionic/af2-lists/src/app/app.module.ts and PatientDetailPageModule in /home/shiva/Ionic/af2-lists/src/pages/patient-detail/patient-detail.module.ts! Please consider moving PatientDetailPage in /home/shiva/Ionic/af2-lists/src/pages/patient-detail/patient-detail.ts to a higher module that imports AppModule in /home/shiva/Ionic/af2-lists/src/app/app.module.ts and PatientDetailPageModule in /home/shiva/Ionic/af2-lists/src/pages/patient-detail/patient-detail.module.ts. You can also create a new NgModule that exports and includes PatientDetailPage in /home/shiva/Ionic/af2-lists/src/pages/patient-detail/patient-detail.ts then import that NgModule in AppModule in /home/shiva/Ionic/af2-lists/src/app/app.module.ts and PatientDetailPageModule in /home/shiva/Ionic/af2-lists/src/pages/patient-detail/patient-detail.module.ts.
at syntaxError (/home/shiva/Ionic/af2-lists/node_modules/@angular/compiler/bundles/compiler.umd.js:1550:34)
at CompileMetadataResolver._addTypeToModule (/home/shiva/Ionic/af2-lists/node_modules/@angular/compiler/bundles/compiler.umd.js:14655:31)
at /home/shiva/Ionic/af2-lists/node_modules/@angular/compiler/bundles/compiler.umd.js:14543:27
at Array.forEach (native)
at CompileMetadataResolver.getNgModuleMetadata (/home/shiva/Ionic/af2-lists/node_modules/@angular/compiler/bundles/compiler.umd.js:14534:54)
at addNgModule (/home/shiva/Ionic/af2-lists/node_modules/@angular/compiler/bundles/compiler.umd.js:23050:58)
at /home/shiva/Ionic/af2-lists/node_modules/@angular/compiler/bundles/compiler.umd.js:23061:14
at Array.forEach (native)
at _createNgModules (/home/shiva/Ionic/af2-lists/node_modules/@angular/compiler/bundles/compiler.umd.js:23060:26)
at analyzeNgModules (/home/shiva/Ionic/af2-lists/node_modules/@angular/compiler/bundles/compiler.umd.js:22935:14)

我知道我多次加载相同的模块,但不知道如何删除它们。

我的 app.module.ts

@NgModule({
imports: [
BrowserModule,
IonicModule.forRoot(MyApp),
AngularFireDatabaseModule,
AngularFireModule.initializeApp(firebaseConfig),
AngularFireOfflineModule,
IonicStorageModule.forRoot()
// PatientDetailPage

],
declarations: [
MyApp,
HomePage,
PatientDetailPage
],
entryComponents: [
MyApp,
HomePage,
PatientDetailPage
],
providers: [
StatusBar,
SplashScreen,
//AngularFireModule,
//Storage,
{provide: ErrorHandler, useClass: IonicErrorHandler}
],
bootstrap: [IonicApp],
})

patient-detail.module.ts 是

import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { PatientDetailPage } from './patient-detail';

@NgModule({
declarations: [
PatientDetailPage,
],
imports: [
IonicPageModule.forChild(PatientDetailPage),
]

})
export class PatientDetailPageModule {

}

最佳答案

这是angular的一个基本错误。可以看到issue here .所以目前接受的答案是使用共享模块。你可以这样做:
- 创建一个 share.module.ts
- Importdeclarationexport 在此 share.module.ts

中您的组件
import { NgModule }       from '@angular/core';
import {SharedComponentA} from "./SharedComponentA";
import {SharedComponentB} from "./SharedComponentB";

@NgModule({
imports: [
],
declarations: [
SharedComponentA,
SharedComponentB

],
providers: [
],
exports: [
SharedComponentA,
SharedComponentB
]
})
export class SharedModule {}


- 如果您想在 Ionic 页面(延迟加载页面) 中使用您的组件,请在该 Ionic 页面的模块中导入共享模块:

import {SharedModule } from './SharedModule';
@NgModule({
imports: [
SharedModule
//..
],
//..
})


- 如果您想在其他组件或无延迟加载页面中使用您的组件,请像上面那样在您的app.module.ts中导入共享模块。
查看更多关于 ngModule

关于angular - 页面是 2 个模块 : Error in ionic build prod 声明的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46159788/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com