加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular – Page是2个模块声明的一部分:离子构建产生错误

发布时间:2020-12-17 17:05:09 所属栏目:安全 来源:网络整理
导读:当我运行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
当我运行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,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 {

}

解决方法

这是角度的基本误差.你可以看到问题 here.所以到目前为止接受的答案是使用共享模块.你可以这样做:
? – 创建一个share.module.ts
? – 在此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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读