简体   繁体   English

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

[英]Ionic 2 : — prod file not compiling Error: build prod failed: Cannot determine the module for class HomePage

I'm trying to build a project with --prod flag It throws an error我正在尝试使用 --prod 标志构建一个项目它会引发错误

 build prod failed: Cannot determine the module for class HomePage

Normal build is working ionic cordova build android正常构建正在运行ionic cordova build android

Previously about a week ago it was working good.大约一周前,它运行良好。 Here is package.json file这是 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 platform : 6.3.0. Cordova Cli:7.1.0 科尔多瓦安卓平台:6.3.0。 Gone through lots of google links but I cant get a proper solution for this.浏览了很多谷歌链接,但我无法为此找到合适的解决方案。

app.module.ts file 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 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;
        });
    }
}

Any Suggestion?有什么建议吗?

You must add your HomePage to the declarations and entryComponents in app.module.ts您必须将 HomePage 添加到entryComponents中的declarations和 entryComponents

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

You may also need to add other pages that are not lazy-loaded.您可能还需要添加其他非延迟加载的页面。 Pages that are lazy-loaded (pages that have there own module), do not need to be added here.延迟加载的页面(有自己的模块的页面),不需要在这里添加。

Found the Solution找到解决方案

As @Sébastien Mentioned to add the pages I did, but I'm not using the HomePage So I removed the page from the project.正如@Sébastien 提到的那样添加我所做的页面,但我没有使用主页所以我从项目中删除了该页面。 For latest Angular version the AOT compiler scans the whole project folder, so it is getting confused which classes are used and which are not.对于最新的 Angular 版本,AOT 编译器会扫描整个项目文件夹,因此会混淆哪些类被使用,哪些没有被使用。 I added the files to declaration part after that it throws an error to add the template.我将文件添加到声明部分之后,它会引发错误以添加模板。

For every Component, I added the below code对于每个组件,我添加了以下代码

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

That's it.就是这样。

@Sébastien your answer is valuable @Sébastien 你的回答很有价值

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Ionic Cordova Build prod:找不到模块“.” - 打字稿版本 &gt;3 - Ionic Cordova Build prod: Cannot find module “.” - Typescript version >3 离子cordova构建android --prod时出错 - Error in ionic cordova build android --prod 在生产模式下执行ionic 2 Android应用程序时出错,找不到模块ngfactory - Error when executing an ionic 2 Android app on prod mode , cannot find module ngfactory 离子科尔多瓦建立android --prod - ionic cordova build android --prod 无法读取离子Cordova构建android --prod --release中的属性 - Cannot read property in ionic cordova build android --prod --release Ionic build android --prod cleancss破坏了@import错误 - Ionic build android --prod cleancss broken @import error 离子科尔多瓦建立android --prod --release错误:app:transformDexWithDexForRelease - ionic cordova build android --prod --release Error :app:transformDexWithDexForRelease 运行ionic cordova build android --prod --release时发生错误 - An error occurred while running ionic cordova build android --prod --release Ionic 构建浏览器 --prod --release 在我为 PWA 构建时显示错误 - Ionic build browser --prod --release showing error when I build for PWA 为什么用&#39;--prod --release android&#39;构建Ionic 3 apk会给Google Playstore错误,表明apk是在调试模式下签名的? - Why is Ionic 3 apk build with '--prod --release android' giving Google playstore error that apk was signed in debug mode?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM