ionic cordova build android --prod 使 JavaScript 堆内存不足

Posted

技术标签:

【中文标题】ionic cordova build android --prod 使 JavaScript 堆内存不足【英文标题】:ionic cordova build android --prod gets a JavaScript heap out of memory 【发布时间】:2021-10-30 17:21:55 【问题描述】:

我正在构建一个 Ionic 3 应用程序。我的 --prod 构建工作正常。突然,我现在使用 --prod 标志使 javascript 堆内存不足。我已经尝试了很多来自网络的东西,但我仍然无法构建产品版本。

这是我的 package.json


  "name": "fusion",
  "version": "0.0.1",
  "author": "Ionic Framework",
  "homepage": "http://ionicframework.com/",
  "private": true,
  "scripts": 
    "clean": "ionic-app-scripts clean",
    "build": "ionic-app-scripts build",
    "lint": "ionic-app-scripts lint",
    "ionic:build": "ionic-app-scripts build",
    "ionic:serve": "ionic-app-scripts serve"
  ,
  "dependencies": 
    "@angular/animations": "5.2.11",
    "@angular/cdk": "^5.2.5",
    "@angular/common": "5.2.11",
    "@angular/compiler": "5.2.11",
    "@angular/compiler-cli": "5.2.11",
    "@angular/core": "5.2.11",
    "@angular/forms": "5.2.11",
    "@angular/http": "5.2.11",
    "@angular/platform-browser": "5.2.11",
    "@angular/platform-browser-dynamic": "5.2.11",
    "@ionic-native/android-permissions": "^4.20.0",
    "@ionic-native/app-version": "^4.20.0",
    "@ionic-native/camera": "^4.20.0",
    "@ionic-native/core": "4.3.2",
    "@ionic-native/file": "^4.20.0",
    "@ionic-native/file-opener": "^4.20.0",
    "@ionic-native/file-path": "^4.20.0",
    "@ionic-native/file-transfer": "^4.20.0",
    "@ionic-native/fingerprint-aio": "^4.20.0",
    "@ionic-native/local-notifications": "^4.20.0",
    "@ionic-native/ms-adal": "^4.20.0",
    "@ionic-native/network": "^4.20.0",
    "@ionic-native/onesignal": "^4.20.0",
    "@ionic-native/qr-scanner": "^4.20.0",
    "@ionic-native/social-sharing": "^4.20.0",
    "@ionic-native/spinner-dialog": "^4.20.0",
    "@ionic-native/splash-screen": "4.3.2",
    "@ionic-native/sqlite": "^4.20.0",
    "@ionic-native/sqlite-porter": "^4.20.0",
    "@ionic-native/status-bar": "4.3.2",
    "@ionic-native/toast": "^4.20.0",
    "@ionic-native/transfer": "^3.14.0",
    "@ionic-native/vibration": "^4.20.0",
    "@ionic/storage": "^2.1.3",
    "@types/jquery": "^2.0.56",
    "@types/node": "^15.12.2",
    "@types/vivus": "^0.4.3",
    "animate.css": "^4.1.0",
    "blob-util": "^2.0.2",
    "buffer": "^5.2.1",
    "chart.js": "^2.7.3",
    "cldr-data": "^36.0.0",
    "concat-stream": "^1.6.2",
    "cordova-android": "^9.0.0",
    "cordova-browser": "5.0.4",
    "cordova-plugin-android-permissions": "^1.0.2",
    "cordova-plugin-androidx": "^3.0.0",
    "cordova-plugin-androidx-adapter": "^1.1.3",
    "cordova-plugin-app-version": "^0.1.9",
    "cordova-plugin-badge": "0.8.8",
    "cordova-plugin-camera": "4.0.3",
    "cordova-plugin-device": "^2.0.2",
    "cordova-plugin-file": "^6.0.1",
    "cordova-plugin-file-opener2": "^3.0.2",
    "cordova-plugin-file-transfer": "1.7.1",
    "cordova-plugin-fingerprint-aio": "^4.0.1",
    "cordova-plugin-ionic-webview": "^4.2.1",
    "cordova-plugin-local-notification": "0.9.0-beta.2",
    "cordova-plugin-native-spinner": "^1.1.3",
    "cordova-plugin-network-information": "^2.0.2",
    "cordova-plugin-splashscreen": "^6.0.0",
    "cordova-plugin-statusbar": "^2.4.2",
    "cordova-plugin-whitelist": "^1.3.3",
    "cordova-plugin-x-toast": "^2.7.2",
    "cordova-sqlite-storage": "^5.0.0",
    "core-js": "^2.5.7",
    "devextreme": "19.1.10",
    "devextreme-angular": "19.1.10",
    "es6-promise-plugin": "^4.2.2",
    "events": "^3.0.0",
    "firebase": "^4.12.1",
    "globalize": "^1.4.2",
    "hammerjs": "^2.0.8",
    "iana-tz-data": "^2019.1.0",
    "intl": "^1.2.5",
    "ion-bottom-drawer": "^1.0.3",
    "ionic-angular": "3.9.10",
    "ionic-image-loader": "^4.2.1",
    "ionic-img-viewer": "^2.9.0",
    "ionic-select-searchable": "^2.10.0",
    "ionic-selectable": "^3.5.0",
    "ionic2-calendar": "^0.4.6",
    "ionicons": "3.0.0",
    "jquery": "^3.6.0",
    "jszip": "^3.1.5",
    "lodash": "^4.17.11",
    "moment": "^2.24.0",
    "ngx-scrollbar": "^4.2.0",
    "ngx-soap": "^0.5.0-beta.7",
    "node-sass": "4.12.0",
    "onesignal-cordova-plugin": "^2.11.2",
    "primeicons": "^1.0.0",
    "primeng": "^5.2.7",
    "request": "^2.88.2",
    "rxjs": "^5.5.11",
    "sax": "^1.2.4",
    "signalr": "^2.4.2",
    "stream": "0.0.2",
    "sw-toolbox": "3.6.0",
    "swagger-typescript-api": "^1.12.0",
    "tracking": "^1.1.3",
    "uk.co.workingedge.cordova.plugin.sqliteporter": "^1.1.1",
    "uuid": "^3.3.2",
    "vivus": "^0.4.5",
    "zone.js": "0.8.18"
  ,
  "devDependencies": 
    "@ionic/app-scripts": "3.2.1",
    "cordova-plugin-compat": "^1.2.0",
    "cordova-plugin-ms-adal": "^0.10.2",
    "cordova-plugin-stetho-android": "0.0.1",
    "cordova-plugin-x-socialsharing": "^6.0.3",
    "typescript": "~2.6.2"
  ,
  "description": "An Ionic project",
  "cordova": 
    "plugins": 
      "cordova-plugin-statusbar": ,
      "cordova-plugin-device": ,
      "cordova-plugin-whitelist": ,
      "cordova-plugin-ionic-webview": 
        "ANDROID_SUPPORT_ANNOTATIONS_VERSION": "27.+"
      ,
      "cordova-plugin-file": ,
      "cordova-plugin-local-notification": ,
      "cordova-plugin-camera": ,
      "cordova-plugin-file-transfer": ,
      "onesignal-cordova-plugin": ,
      "cordova-sqlite-storage": ,
      "cordova-plugin-native-spinner": ,
      "cordova-plugin-x-toast": ,
      "cordova-plugin-network-information": ,
      "cordova-plugin-x-socialsharing": ,
      "cordova-plugin-file-opener2": 
        "ANDROID_SUPPORT_V4_VERSION": "27.+"
      ,
      "cordova-plugin-app-version": ,
      "cordova-plugin-android-permissions": ,
      "cordova-plugin-splashscreen": ,
      "cordova-plugin-androidx-adapter": ,
      "cordova-plugin-fingerprint-aio": ,
      "uk.co.workingedge.cordova.plugin.sqliteporter": ,
      "com.outsystems.mobile.stetho": ,
      "cordova-plugin-ms-adal": 
    ,
    "platforms": [
      "android",
      "browser"
    ]
  

我使用的是 Ionic 3 和 Node V13.12.0

这到底是什么问题?

提前致谢!

【问题讨论】:

这能回答你的问题吗? Heap out of memory in angular4 while ng build --prod 增加节点选项 max_old_space_size 没有帮助 【参考方案1】:

在运行ionic cordova build android --prod之前在终端中运行它

export NODE_OPTIONS=--max_old_space_size=4096

【讨论】:

以上是关于ionic cordova build android --prod 使 JavaScript 堆内存不足的主要内容,如果未能解决你的问题,请参考以下文章

ionic cordova build 显示 lint 警告

ionic cordova build android 报错 解决

Ionic Cordova Build Android 期间面临错误

ionic cordova build android - 失败

使用 CMD 行构建失败 --ionic cordova build android

安装cordova push插件后,Ionic build ios失败