Ionic 2 : -- prod 文件未编译 错误: 构建产品失败: 无法确定类主页的模块



>我正在尝试使用 --prod 标志构建一个项目 它抛出一个错误

 build prod failed: Cannot determine the module for class HomePage

正常构建正在工作ionic cordova build android

大约一周前,它运行良好。这是包.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"
      }
    }
  }
}

科尔多瓦 CLI : 7.1.0科尔多瓦安卓平台: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;
        });
    }
}

有什么建议吗?

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

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

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

找到了解决方案

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

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

@Component({
    selector: 'DbLoginService',
    template: '<span></span>'
})

就是这样。

@Sébastien你的答案是有价值的

相关内容

  • 没有找到相关文章

最新更新