Ionic 2: - prod文件未编译错误:build prod failed:无法确定类HomePage的模块

时间:2018-01-28 12:17:27

标签: android angularjs cordova typescript ionic2

我尝试使用--prod标志构建项目它会抛出错误

 build prod failed: Cannot determine the module for class HomePage

正常构建工作ionic cordova build android

此前大约一周前它运作良好。这是package.json文件

{
  "name": "io.cordova.myapp882994",
  "author": "",
  "homepage": "",
  "private": true,
  "scripts": {
    "clean": "ionic-app-scripts clean",
    "build": "ionic-app-scripts build",
    "ionic:build": "ionic-app-scripts build",
    "ionic:serve": "ionic-app-scripts serve",
    "watch": "ionic-app-scripts watch"
  },
  "dependencies": {
    "@angular/common": "2.2.1",
    "@angular/compiler": "2.2.1",
    "@angular/compiler-cli": "2.2.3",
    "@angular/core": "2.2.1",
    "@angular/forms": "2.2.1",
    "@angular/http": "2.2.1",
    "@angular/platform-browser": "2.2.1",
    "@angular/platform-browser-dynamic": "2.2.1",
    "@angular/platform-server": "2.2.1",
    "@ionic-native/app-minimize": "^4.2.1",
    "@ionic-native/call-number": "^4.3.2",
    "@ionic-native/core": "^3.6.1",
    "@ionic-native/diagnostic": "^4.5.2",
    "@ionic-native/fcm": "^4.5.2",
    "@ionic-native/geolocation": "^4.1.0",
    "@ionic-native/local-notifications": "^4.5.2",
    "@ionic-native/native-storage": "^4.1.0",
    "@ionic-native/network": "^4.3.1",
    "@ionic-native/open-native-settings": "^4.3.1",
    "@ionic-native/push": "^4.5.2",
    "@ionic-native/secure-storage": "^4.1.0",
    "@ionic-native/splash-screen": "^4.2.0",
    "@ionic/storage": "^1.1.9",
    "call-number": "^1.0.1",
    "cordova-android": "6.3.0",
    "cordova-ios": "4.2.0",
    "cordova-open-native-settings": "^1.4.1",
    "cordova-plugin-app-event": "~1.2.1",
    "cordova-plugin-appminimize": "~1.0",
    "cordova-plugin-compat": "^1.2.0",
    "cordova-plugin-console": "1.0.5",
    "cordova-plugin-crosswalk-webview": "~2.4.0",
    "cordova-plugin-device": "1.1.4",
    "cordova-plugin-geolocation": "~2.4.3",
    "cordova-plugin-nativestorage": "~2.2.2",
    "cordova-plugin-network-information": "^1.3.3",
    "cordova-plugin-splashscreen": "~4.0.1",
    "cordova-plugin-statusbar": "2.2.1",
    "cordova-plugin-whitelist": "1.3.1",
    "cordova-windows": "4.4.2",
    "cordova.plugins.diagnostic": "^3.9.1",
    "de.appplant.cordova.plugin.local-notification": "^0.8.5",
    "ionic-angular": "2.0.1",
    "ionic-native": "2.4.1",
    "ionic-plugin-keyboard": "~2.2.1",
    "ionic2-rating": "^1.2.2",
    "ionicons": "3.0.0",
    "mx.ferreyra.callnumber": "~0.0.2",
    "phonegap-plugin-push": "~2.1.2",
    "rxjs": "5.0.0-beta.12",
    "sw-toolbox": "3.4.0",
    "zone.js": "0.6.26"
  },
  "devDependencies": {
    "@ionic/app-scripts": "1.1.0",
    "typescript": "2.0.9"
  },
  "description": "Ionic2Blank: An Ionic project",
  "cordovaPlugins": [
    "cordova-plugin-whitelist",
    "cordova-plugin-console",
    "cordova-plugin-statusbar",
    "cordova-plugin-device",
    "cordova-plugin-splashscreen",
    "ionic-plugin-keyboard"
  ],
  "cordovaPlatforms": [],
  "-vs-binding": {
    "BeforeBuild": [
      "ionic:build"
    ]
  },
  "cordova": {
    "platforms": [
      "ios",
      "windows",
      "android"
    ],
    "plugins": {
      "cordova-plugin-appminimize": {},
      "cordova-plugin-console": {},
      "cordova-plugin-device": {},
      "cordova-plugin-geolocation": {},
      "cordova-plugin-nativestorage": {},
      "cordova-plugin-splashscreen": {},
      "cordova-plugin-statusbar": {},
      "cordova-plugin-whitelist": {},
      "ionic-plugin-keyboard": {},
      "cordova-plugin-network-information": {},
      "cordova-open-native-settings": {},
      "mx.ferreyra.callnumber": {},
      "de.appplant.cordova.plugin.local-notification": {},
      "cordova-plugin-compat": {},
      "cordova-plugin-app-event": {},
      "cordova.plugins.diagnostic": {},
      "cordova-plugin-crosswalk-webview": {
        "XWALK_VERSION": "23+",
        "XWALK_LITEVERSION": "xwalk_core_library_canary:17+",
        "XWALK_COMMANDLINE": "--disable-pull-to-refresh-effect",
        "XWALK_MODE": "embedded",
        "XWALK_MULTIPLEAPK": "true"
      },
      "phonegap-plugin-push": {
        "SENDER_ID": "XXXXXXXXXXXX"
      }
    }
  }
}

Cordova Cli:7.1.0 cordova android平台:6.3.0。通过大量的谷歌链接,但我无法得到一个适当的解决方案。

app.module.ts文件

import { NgModule, ErrorHandler } from '@angular/core';
import { IonicApp, IonicModule, IonicErrorHandler, NavController } from 'ionic-angular';
import { Geolocation } from '@ionic-native/geolocation';
import { AppMinimize } from '@ionic-native/app-minimize';
import { OpenNativeSettings } from '@ionic-native/open-native-settings';

import { MyApp } from './app.component';
import { loginPage } from '../pages/login/login';
import { loginService } from '../providers/loginservice/loginservice';
import { dashboardPage } from '../pages/dashboard/dashboard';
import { ActivitiesPage } from '../pages/activities/activities';
import { ActiveService } from '../providers/activeServices/activeServices';
import { locationCompleteService } from '../providers/locationService/locationCompleteService'; 
import { locationUpcomingService } from '../providers/locationService/locationUpcomingService';

import { InvoicePage } from '../pages/invoice/invoice';
import { invoiceService } from '../providers/invoiceService/invoiceService';
import { feedbackPage } from '../pages/feedback/feedback';
import { UpComingService } from '../providers/UpcomingService/upcomingActivityService';
import { Helper } from '../pages/Helper';
import { FeedbackService } from '../providers/feedbackService/FeedbackService';

import { samplePage } from '../pages/sample/sample';
import { locationUpdatePage } from '../pages/locationUpdate/locationUpdate'
import { locationService } from '../providers/locationupdateservice/locationservice';
import { locationUpdate } from '../providers/locationupdateservice/locationUpdate';

import { scopeofworkPage } from '../pages/scopeofwork/scopeofwork'
import { scopeofworkservice } from '../providers/scopeofwork/scopeofworkservice';

import { SchedulePage } from '../pages/Schedule/Schedule';
import { waypointPage } from '../pages/waypoint/waypoint';
import { Ionic2RatingModule } from 'ionic2-rating';
import { ScheduleService } from '../providers/scheduleService/scheduleService';

import { NativeStorage } from '@ionic-native/native-storage';
import { SplashScreen } from '@ionic-native/splash-screen';

import { userPrevilages } from '../userPrevilages';
import { CallNumber } from '@ionic-native/call-number';
import { otService } from '../providers/otservice/otService';
import { Push, PushObject, PushOptions } from '@ionic-native/push';
import { pushNotificationService } from '../providers/pushnotificationService/pushNotificationService';
import { LocalNotifications } from '@ionic-native/local-notifications';
import { Diagnostic } from '@ionic-native/diagnostic';

@NgModule({
    declarations: [
        MyApp,
        dashboardPage,
        loginPage,
        ActivitiesPage,
        InvoicePage,
        feedbackPage,
        samplePage,
        locationUpdatePage,
        scopeofworkPage,
        SchedulePage,
        waypointPage
    ],
    imports: [
        IonicModule.forRoot(MyApp),
        Ionic2RatingModule
    ],
    bootstrap: [IonicApp],
    entryComponents: [
        MyApp,
        loginPage,
        dashboardPage,
        ActivitiesPage,
        InvoicePage,
        feedbackPage,
        samplePage,
        locationUpdatePage,
        scopeofworkPage,
        SchedulePage,
        waypointPage   
    ],
    providers:
    [
        Helper,
        loginService,
        Geolocation,
        UpComingService,
        ActiveService,
        locationCompleteService,
        FeedbackService,
        locationService,
        locationUpdate,
        invoiceService,
        scopeofworkservice,
        ScheduleService,
        NativeStorage,
        OpenNativeSettings,
        userPrevilages,
        CallNumber,
        otService,
        Push,
        pushNotificationService,
        LocalNotifications,
        Diagnostic,

        Diagnostic,
        {
            provide: ErrorHandler, useClass: IonicErrorHandler
        },
        SplashScreen,
        AppMinimize
    ]
})
export class AppModule {}

app.component.ts

import { Component, ViewChild } from '@angular/core';
import { Nav, Platform, ToastController, LoadingController, AlertController, NavController, IonicApp } from 'ionic-angular';
import { StatusBar, Splashscreen, Network } from 'ionic-native';
import { AppMinimize } from '@ionic-native/app-minimize';
import { HomePage } from '../pages/home/home';
import { loginPage } from '../pages/login/login';

import { Helper } from '../pages/Helper';

import { Diagnostic } from 'ionic-native';
import { Observable } from "rxjs/Observable";

declare var navigator: any;
declare var Connection: any;

@Component({
    templateUrl: 'app.html',
    selector: 'app',    
})

export class MyApp  {
    @ViewChild(Nav) nav: Nav;
    rootPage: any;

    constructor(public platform: Platform, public help: Helper) {
        this.initializeApp();
    }

    initializeApp() {
        this.platform.ready().then(() => {
            // Okay, so the platform is ready and our plugins are available.
            // Here you can do any higher level native things you might need.
            StatusBar.styleDefault();
            this.rootPage = loginPage;
        });
    }
}

有任何建议吗?

2 个答案:

答案 0 :(得分:1)

您必须将自己的主页添加到app.module.ts中的declarationsentryComponents

declarations: [
    MyApp,
    HomePage,
    ...
  ],
  ....
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    HomePage,
    ...
  ],

您可能还需要添加其他非延迟加载的页面。延迟加载的页面(具有自己模块的页面)不需要在这里添加。

答案 1 :(得分:0)

找到解决方案

As @Sébastien提到要添加我所做的页面,但我没有使用HomePage所以我从项目中删除了页面。对于最新的Angular版本,AOT编译器会扫描整个项目文件夹,因此会混淆使用哪些类,哪些不是。我将文件添加到声明部分之后,它会引发错误以添加模板。

对于每个组件,我添加了以下代码

awk

就是这样。

@Sébastien你的回答很有价值