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

Posted

技术标签:

【中文标题】Ionic 2 : -- prod 文件未编译错误:构建 prod 失败:无法确定类 HomePage 的模块【英文标题】:Ionic 2 : -- prod file not compiling Error: build prod failed: Cannot determine the module for class HomePage 【发布时间】:2018-07-07 06:19:04 【问题描述】:

我正在尝试使用 --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"
      
    
  

科尔多瓦 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;
        );
    

有什么建议吗?

【问题讨论】:

您是否在为您的页面使用延迟加载?请分享您的主要模块和组件 @Sébastien 检查上面我已添加 【参考方案1】:

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

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

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

【讨论】:

这个类还有 loginService, UpComingService, ActiveService, locationCompleteService, FeedbackService, locationService, locationUpdate, invoiceService, scopeofworkservice, ScheduleService, otService 我不懂你们的cmets...什么是主页? HomePage 是 ionic Page 的一个类。对于以下课程,我也遇到了同样的错误。此类不是 Ionic 页面,此类用于使用 Rest API 从服务中获取数据“loginService, UpComingService, ActiveService, locationCompleteService, FeedbackService, locationService, locationUpdate, invoiceService, scopeofworkservice, ScheduleService, otService” 如果与我的回答无关,请考虑解释您所做的事情。 当然@Sebastine 我会解释【参考方案2】:

找到解决办法

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

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

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

就是这样。

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

【讨论】:

以上是关于Ionic 2 : -- prod 文件未编译错误:构建 prod 失败:无法确定类 HomePage 的模块的主要内容,如果未能解决你的问题,请参考以下文章

Ionic angular prod 编译器错误属性“md”在类型上不存在

Ionic 3:在“prod”模式下构建:找不到模块“。”

运行 ionic ios build --prod --release 时出错

ionic cordova build --prod --release 失败并产生错误

Ionic 3 - 使用 --prod 标志运行时,sqlite 显示“无法读取 openDatabase 的属性”的错误

页面是 2 个模块声明的一部分:Error in ionic build prod