[英]Page in Ionic is part of the declarations of 2 modules
我有一個 ionic 3 項目,文件 app.module.ts 是這樣的:
@NgModule({
declarations: [
MyApp,
HomePage,
AdminPage,
ActuDetailPage,
],...
當我在我的 android 設備上部署為 dev 時,沒問題,但是當我使用 --prod --release 參數進行部署時,我收到以下錯誤消息:
Type ActuDetailPage in /Users/poste5hookipa/sites/frApp4/src/pages/actu-detail/actu-detail.ts is part of the
declarations of 2 modules: AppModule in /Users/poste5hookipa/sites/frApp4/src/app/app.module.ts and
ActuDetailPageModule in /Users/poste5hookipa/sites/frApp4/src/pages/actu-detail/actu-detail.module.ts!
Please consider moving ActuDetailPage in
/Users/poste5hookipa/sites/frApp4/src/pages/actu-detail/actu-detail.ts to a higher module that imports
AppModule in /Users/poste5hookipa/sites/frApp4/src/app/app.module.ts and ActuDetailPageModule in
/Users/poste5hookipa/sites/frApp4/src/pages/actu-detail/actu-detail.module.ts. You can also create a new
NgModule that exports and includes ActuDetailPage in
/Users/poste5hookipa/sites/frApp4/src/pages/actu-detail/actu-detail.ts then import that NgModule in
AppModule in /Users/poste5hookipa/sites/frApp4/src/app/app.module.ts and ActuDetailPageModule in
/Users/poste5hookipa/sites/frApp4/src/pages/actu-detail/actu-detail.module.ts.
所以我必須像這樣取消評論:
@NgModule({
declarations: [
MyApp,
HomePage,
/* AdminPage,
ActuDetailPage,*/
對於后者,我可以部署為 prod,但使用相同的注釋,在 dev 中部署會產生錯誤。 如何組織代碼以使其符合 dev 和 prod? 謝謝
您可以創建一個Shared Module ,在其中聲明 Page 組件並將其添加到exports數組中
然后在你提到的2個模塊中導入共享模塊。
像這樣:
共享模塊:
@NgModule({
imports: [
...
],
declarations: [
AdminPage,
ActuDetailPage
],
exports: [
AdminPage,
ActuDetailPage
]
})
export class SharedModule { }
模塊 1 和模塊 2 :
@NgModule({
imports: [
SharedModule,
...
]
我終於擺脫了這個問題,消息只是說該模塊不屬於任何模塊,並將 actu-detail.ts 放在模塊文件中。 actu-detail.ts 確實是在ActuDetailPageModule 中聲明的,但是ActuDetailPageModule 並沒有被導入到AppModule 中。
在app.module.ts中,在@NgModule中,imports屬性是一個modules數組,我簡單的添加了AdminPageModule,ActuDetailPageModule來解決這個問題。
@NgModule({
declarations: [
MyApp,
HomePage,
],
imports: [
AdminPageModule,
ActuDetailPageModule,
....],
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.