无法构建 Ionic 2 项目



我将 ionic 2 项目迁移到最新版本(即 3.0.0(。一切都很完美,直到我今天在项目中生成了一个新页面(DiscountOption(。它生成了 4 个文件而不是 3 个(*.module.ts 是新的(。

这是我的代码:

discount-option.module.ts

import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { DiscountOption } from './discount-option';
@NgModule({
  declarations: [
    DiscountOption,
  ],
  imports: [
    IonicPageModule.forChild(DiscountOption),
  ],
  exports: [
    DiscountOption
  ]
})
export class DiscountOptionModule { }

app.module.ts

...
import { DiscountOption } from '../pages/orders/biller/discount-option/discount-option';
@NgModule({
  declarations: [
    ...
    DiscountOption
  ],
  imports: [
    BrowserModule,
    HttpModule,
    IonicModule.forRoot(MyApp),
    IonicStorageModule.forRoot()
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    ...
    DiscountOption
  ],
  providers: [
    ...
  ]
})
export class AppModule { }

(...为简洁起见,代码缩短(

当我尝试使用ionic build android --prod构建应用程序时

我收到此错误,

[11:35:52]  ionic-app-script task: "build"
[11:35:52]  Error: Type DiscountOption in E:/TFS
            SOURCE/HMS/HMS.App/eKot/src/pages/orders/biller/discount-option/discount-option.ts is part of the
            declarations of 2 modules: AppModule in E:/TFS SOURCE/HMS/HMS.App/eKot/src/app/app.module.ts and
            DiscountOptionModule in E:/TFS
            SOURCE/HMS/HMS.App/eKot/src/pages/orders/biller/discount-option/discount-option.module.ts! Please consider
            moving DiscountOption in E:/TFS
            SOURCE/HMS/HMS.App/eKot/src/pages/orders/biller/discount-option/discount-option.ts to a higher module that
            imports AppModule in E:/TFS SOURCE/HMS/HMS.App/eKot/src/app/app.module.ts and DiscountOptionModule in E:/TFS
            SOURCE/HMS/HMS.App/eKot/src/pages/orders/biller/discount-option/discount-option.module.ts. You can also
            create a new NgModule that exports and includes DiscountOption in E:/TFS
            SOURCE/HMS/HMS.App/eKot/src/pages/orders/biller/discount-option/discount-option.ts then import that NgModule
            in AppModule in E:/TFS SOURCE/HMS/HMS.App/eKot/src/app/app.module.ts and DiscountOptionModule in E:/TFS
            SOURCE/HMS/HMS.App/eKot/src/pages/orders/biller/discount-option/discount-option.module.ts.
Error: Type DiscountOption in E:/TFS SOURCE/HMS/HMS.App/eKot/src/pages/orders/biller/discount-option/discount-option.ts is part of
 the declarations of 2 modules: AppModule in E:/TFS SOURCE/HMS/HMS.App/eKot/src/app/app.module.ts and DiscountOptionModule in E:/T
FS SOURCE/HMS/HMS.App/eKot/src/pages/orders/biller/discount-option/discount-option.module.ts! Please consider moving DiscountOptio
n in E:/TFS SOURCE/HMS/HMS.App/eKot/src/pages/orders/biller/discount-option/discount-option.ts to a higher module that imports App
Module in E:/TFS SOURCE/HMS/HMS.App/eKot/src/app/app.module.ts and DiscountOptionModule in E:/TFS SOURCE/HMS/HMS.App/eKot/src/page
s/orders/biller/discount-option/discount-option.module.ts. You can also create a new NgModule that exports and includes DiscountOp
tion in E:/TFS SOURCE/HMS/HMS.App/eKot/src/pages/orders/biller/discount-option/discount-option.ts then import that NgModule in App
Module in E:/TFS SOURCE/HMS/HMS.App/eKot/src/app/app.module.ts and DiscountOptionModule in E:/TFS SOURCE/HMS/HMS.App/eKot/src/page
s/orders/biller/discount-option/discount-option.module.ts.
at Error (native)
    at syntaxError (E:TFS SOURCEHMSHMS.AppeKotnode_modules@angularcompilerbundlescompiler.umd.js:1513:34)
    at CompileMetadataResolver._addTypeToModule (E:TFS SOURCEHMSHMS.AppeKotnode_modules@angularcompilerbundlescompiler.um
d.js:14118:31)
    at E:TFS SOURCEHMSHMS.AppeKotnode_modules@angularcompilerbundlescompiler.umd.js:14007:27
    at Array.forEach (native)
    at CompileMetadataResolver.getNgModuleMetadata (E:TFS SOURCEHMSHMS.AppeKotnode_modules@angularcompilerbundlescompiler
.umd.js:13998:54)
    at addNgModule (E:TFS SOURCEHMSHMS.AppeKotnode_modules@angularcompilerbundlescompiler.umd.js:22526:58)
    at E:TFS SOURCEHMSHMS.AppeKotnode_modules@angularcompilerbundlescompiler.umd.js:22537:14
    at Array.forEach (native)
    at _createNgModules (E:TFS SOURCEHMSHMS.AppeKotnode_modules@angularcompilerbundlescompiler.umd.js:22536:26)

我知道此错误是由于在 app.module 和新生成的模块文件中声明模块两次造成的。我不知道如何让它工作。任何建议都会有所帮助。谢谢。

这是我的离子信息

E:\TFS SOURCE\HMS\HMS.App\eKot>ionic info

您的系统信息:

Cordova CLI: 6.5.0
Ionic Framework Version: 3.0.0
Ionic CLI Version: 2.2.2
Ionic App Lib Version: 2.2.1
Ionic App Scripts Version: 1.3.0
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Windows 10
Node Version: v6.10.0
Xcode version: Not installed

查看有关 ionic v3 的 google 文档。

app.module.ts 中删除对DiscountOption页面的任何引用。

@NgModule({
  declarations: [
    ...
  ],
  imports: [
    BrowserModule,
    HttpModule,
    IonicModule.forRoot(MyApp),
    IonicStorageModule.forRoot()
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    ...
  ],
  providers: [
    ...
  ]
})
export class AppModule { }

您的页面将在 page.module.ts 中被引用和声明

如果要将页面导入到其他任何位置,请将其删除.. 使用类名等效的字符串。同时在DiscountOption中添加@IonicPage()

@IonicPage()
@Component({
  templateUrl: 'discount-option.html'
})
export class DiscountOption {}

参考资料:爱奥尼奥尼页面

如果您

不使用Ionic 3延迟加载功能,只需删除页面的yourPage.module.ts即可。这是一个可选的

相关内容

  • 没有找到相关文章