无法建立Ionic 2项目

时间:2017-04-07 06:09:57

标签: android angular ionic2

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

这是我的代码:

量贩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 SOURCE\HMS\HMS.App\eKot\node_modules\@angular\compiler\bundles\compiler.umd.js:1513:34)
    at CompileMetadataResolver._addTypeToModule (E:\TFS SOURCE\HMS\HMS.App\eKot\node_modules\@angular\compiler\bundles\compiler.um
d.js:14118:31)
    at E:\TFS SOURCE\HMS\HMS.App\eKot\node_modules\@angular\compiler\bundles\compiler.umd.js:14007:27
    at Array.forEach (native)
    at CompileMetadataResolver.getNgModuleMetadata (E:\TFS SOURCE\HMS\HMS.App\eKot\node_modules\@angular\compiler\bundles\compiler
.umd.js:13998:54)
    at addNgModule (E:\TFS SOURCE\HMS\HMS.App\eKot\node_modules\@angular\compiler\bundles\compiler.umd.js:22526:58)
    at E:\TFS SOURCE\HMS\HMS.App\eKot\node_modules\@angular\compiler\bundles\compiler.umd.js:22537:14
    at Array.forEach (native)
    at _createNgModules (E:\TFS SOURCE\HMS\HMS.App\eKot\node_modules\@angular\compiler\bundles\compiler.umd.js:22536:26)

我知道这个错误是由于在app.module和新生成的模块文件中声明了两次模块。我不知道如何让它发挥作用。任何意见将是有益的。谢谢。

这是我的离子信息

E:\ TFS SOURCE \ HMS \ HMS.App \ eKot>离子信息

您的系统信息:

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

2 个答案:

答案 0 :(得分:2)

检查google docs regarding ionic v3

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

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

您的页面将在 page.module.ts

中被引用和声明

如果您要在其他地方导入页面,请将其删除..使用等同于类名的字符串。另外在@IonicPage()中添加DiscountOption

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

参考:IonicPage

答案 1 :(得分:1)

如果您未使用Ionic 3延迟加载功能,请删除您的网页yourPage.module.ts。这是可选