angular - ** ionic build --prod** build 给出 FATAL ERROR: Ineffective mark-compacts near heap limit 分配失败 - JavaScript 堆内存不足
问题描述
致命错误:堆限制附近的无效标记压缩分配失败 - JavaScript 堆内存不足。我进入高级系统设置-> 环境变量添加新的“NODE_OPTIONS=--max-old-space-size=7168”但仍然出现相同的错误[JavaScript 堆内存不足]。我有 8GB RAM 系统。
[enter image description here][1]
[enter image description here][2]
包.json
"name": "@chat21/chat21-ionic",
"version": "1.0.16",
"author": "Dario De Pascalis - Frontiere21 SRL",
"license": "AGPL-3.0",
"homepage": "https://www.tiledesk.com",
"repository": {
"type": "git",
"url": "https://github.com/chat21/chat21-ionic"
},
"private": false,
"bin": {
"chat21-ionic": "./bin/chat21-ionic"
},
"scripts": {
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"start": "node server.js",
"lint": "ionic-app-scripts lint",
"ionic:serve": "ionic-app-scripts serve",
"compodoc": "./node_modules/.bin/compodoc -d ./docs/ -p ./tsconfig.json",
"postinstall": "ionic cordova platform add browser --save && ionic cordova build browser",
"ionic:build": "node --max-old-space-size=7168 ./node_modules/@ionic/app-scripts/bin/ionic-app-scripts.js build"
},
"dependencies": {
"@angular/animations": "7.2.9",
"@angular/common": "7.2.9",
"@angular/compiler": "7.2.9",
"@angular/compiler-cli": "7.2.9",
"@angular/core": "7.2.9",
"@angular/forms": "7.2.9",
"@angular/http": "7.2.9",
"@angular/platform-browser": "7.2.9",
"@angular/platform-browser-dynamic": "7.2.9",
"@ionic-native/core": "^5.2.0",
"@ionic-native/file": "^5.2.0",
"@ionic-native/keyboard": "5.2.0",
"@ionic-native/native-storage": "^4.20.0",
"@ionic-native/push": "5.2.0",
"@ionic-native/splash-screen": "5.2.0",
"@ionic-native/sqlite": "5.2.0",
"@ionic-native/sqlite-porter": "5.2.0",
"@ionic-native/status-bar": "5.2.0",
"@ionic/cli-plugin-cordova": "1.6.2",
"@ionic/storage": "2.2.0",
"@ngx-translate/core": "^11.0.1",
"@ngx-translate/http-loader": "^4.0.0",
"add": "^2.0.6",
"angular-linky": "^1.2.2",
"build": "^0.1.4",
"cordova": "^9.0.0",
"cordova-android": "^8.0.0",
"cordova-browser": "^6.0.0",
"cordova-ios": "^5.0.0",
"cordova-osx": "4.0.2",
"cordova-plugin-console": "^1.1.0",
"cordova-plugin-device": "^1.1.7",
"cordova-plugin-nativestorage": "^2.3.2",
"cordova-plugin-splashscreen": "^4.1.0",
"cordova-plugin-statusbar": "^2.4.2",
"cordova-plugin-whitelist": "^1.3.3",
"cordova-sqlite-storage": "^2.6.0",
"device": "^0.3.9",
"express": "^4.16.4",
"firebase": "5.9.0",
"ionic-angular": "3.9.4",
"ionic-plugin-keyboard": "^2.2.1",
"ionicons": "4.5.5",
"macos": "0.0.1",
"material-design-icons": "^3.0.1",
"moment": "^2.24.0",
"npm": "^6.13.1",
"phonegap-plugin-push": "^2.2.3",
"promise-polyfill": "8.1.0",
"rxjs": "6.4.0",
"rxjs-compat": "^6.4.0",
"sw-toolbox": "3.6.0",
"uk.co.workingedge.cordova.plugin.sqliteporter": "^1.1.0",
"zone.js": "0.8.29"
},
"resolutions": {
"grpc": "^1.12.0"
},
"devDependencies": {
"@angular/cli": "^7.3.6",
"@angular/tsc-wrapped": "^4.4.6",
"@ionic/app-scripts": "3.2.4",
"@ionic/cli-plugin-proxy": "^1.5.9",
"typescript": "3.1.6"
},
"cordovaPlugins": [
"cordova-plugin-whitelist",
"cordova-plugin-console",
"cordova-plugin-device",
"cordova-plugin-statusbar",
"cordova-plugin-splashscreen",
"ionic-plugin-keyboard"
],
"cordovaPlatforms": [
"ios",
{
"platform": "ios",
"version": "",
"locator": "ios"
}
],
"description": "listaUtenti: An Ionic project",
"cordova": {
"plugins": {
"cordova-sqlite-storage": {},
"uk.co.workingedge.cordova.plugin.sqliteporter": {},
"cordova-plugin-console": {},
"cordova-plugin-device": {},
"cordova-plugin-splashscreen": {},
"cordova-plugin-statusbar": {},
"cordova-plugin-whitelist": {},
"ionic-plugin-keyboard": {},
"phonegap-plugin-push": {
"SENDER_ID": "10454545458"
},
"cordova-plugin-nativestorage": {}
},
"platforms": [
"android",
"browser",
"osx"
]
}
}````
[1]: https://i.stack.imgur.com/b1sZV.png
[2]: https://i.stack.imgur.com/dxurd.png
解决方案
我认为您在项目中使用了 Firebase。
我找到了论坛上一条旧消息中指出的解决方案:https ://forum.ionicframework.com/t/3-7-0-ios-build-with-prod-not-working/107061/ 24
打开 node_modules/@ionic/app-scripts/bin/ionic-app-scripts.js
将第一行从:
!/usr/bin/env 节点
进入
!/usr/bin/env 节点 --max-old-space-size=4096
我尝试了值 1024 和 2048,但对于我相对较大的应用程序,我需要 4096。
现在我可以运行 ionic cordova build android --prod --release 而没有 FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory 错误。