简体   繁体   English

离子cordova构建android --prod时出错

[英]Error in ionic cordova build android --prod

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory 致命错误:CALL_AND_RETRY_LAST分配失败 - JavaScript堆内存不足

Error when running command: ionic cordova build android --prod 运行命令时出错: ionic cordova build android --prod

Note: that ionic build android , ionic run android and ionic serve all works fine. 注意: 离子构建android离子运行android离子服务都可以正常工作。

I've read many topics that says once the project gets bigger, it stops working. 我读过许多话题,说一旦项目变大,就会停止工作。

It was working the day before issue arrive. 它是在问题到来前一天工作的。 It stopped working as we added more files and JSON for translation of app in multi-language. 它停止工作,因为我们添加了更多的文件和JSON,用于多语言的应用程序翻译。

Is it a known issue? 这是一个已知的问题吗? Is there any solution? 有什么解决方案吗?

PLEASE CHECK FOR MORE DETAIL : https://youtu.be/oCN7iSt8rzg 请检查更多细节: https//youtu.be/oCN7iSt8rzg

Attached Error Image: 附加错误图片:

在此输入图像描述

Ionic Info: 离子信息:

在此输入图像描述

Resolved by modifying my ionic.cmd file in C:\\Users\\AppData\\Roaming\\npm by adding --max_old_space_size . 通过添加--max_old_space_size修改C:\\ Users \\ AppData \\ Roaming \\ npm中的ionic.cmd文件解决了该问题 I set mine to 8096 . 我把我的定为8096

 @if EXIST "%~dp0\\node.exe" ( "%~dp0\\node.exe" --max_old_space_size=8096 "%~dp0\\node_modules\\ionic\\bin\\ionic" %* ) ELSE ( @SETLOCAL @set PATHEXT=%PATHEXT:;.JS;=;% node --max_old_space_size=8096 "%~dp0\\node_modules\\ionic\\bin\\ionic" %* ) 

Good luck! 祝好运! Check Actual Source: https://github.com/ionic-team/ionic-cli/issues/1453 检查实际来源: https//github.com/ionic-team/ionic-cli/issues/1453

My ionic (Ionic CLI) : 3.20.0 and @ionic/app-scripts : 3.1.8 but was still getting the error. 我的离子(离子CLI):3.20.0和@ ionic / app-scripts:3.1.8但仍然出现错误。

I fixed the error by updating the build script in package.json 我通过更新package.json中的构建脚本来修复错误

  "scripts": {
    "clean": "ionic-app-scripts clean",
    "build": "node --max-old-space-size=2048 ./node_modules/.bin/ionic-app-scripts build",
    "lint": "ionic-app-scripts lint",
    "ionic:build": "ionic-app-scripts build",
    "ionic:serve": "ionic-app-scripts serve"
  },

or 要么

Try the below command: 尝试以下命令:

$ sudo node --max-old-space-size=4096 /usr/local/bin/ionic cordova build android --prod $ sudo node --max-old-space-size = 4096 / usr / local / bin / ionic cordova build android --prod

I also encountered this error and I told myself that increasing the allocated memory was a workaround as something must be going wrong under the hood. 我也遇到了这个错误,我告诉自己增加分配的内存是一种解决方法,因为必须在引擎盖下出错。

If you are using Firebase , it turns out that it is the culprit. 如果你使用的是Firebase ,事实证明它是罪魁祸首。

I changed it from "^4.12.1" to "4.6.1" (without the caret symbol) and ran npm install to downgrade it to the said anterior version. 我将它从“^ 4.12.1”更改为“4.6.1”(没有插入符号)并运行npm install将其降级为所述前版本。

After that, I was able to run ionic cordova build android --prod without encountering the dreaded "heap out of memory" error. 之后,我能够运行ionic cordova build android --prod而不会遇到可怕的“堆内存不足”错误。

Apparently, 4.12.1 (and perhaps others) has a memory leak, hence the encountered issue. 显然,4.12.1(也许还有其他人)有内存泄漏,因此遇到了问题。

Hope this helps! 希望这可以帮助!

Even though the issue is resolved by the OP, it's a temporary workaround. 即使问题由OP解决,这也是一个临时的解决方法。 The actual issue is something to do with the string operations that is involved in the project. 实际问题与项目中涉及的字符串操作有关。

As the OP has already mentioned that the project involves JSON strings of huge size, the ideal fix will be track down the memory consumption during build using tools like node-memwatch and fix the same. 由于OP已经提到该项目涉及大尺寸的JSON字符串,理想的修复方法是使用node-memwatch等工具跟踪构建期间的内存消耗并修复相同的内容。 Setting heap size of approximately 8GB may not be possible all the time and this has to increase with the further enhancements in the project too. 设置堆大小大约为8GB可能无法一直存在,并且随着项目的进一步增强,这必须增加。

Also as per this link , the latest webpack release will hopefully ease out some of these problems. 此外,根据此链接 ,最新的webpack版本将有望缓解其中一些问题。

UPDATE: you can also try using latest Ionic CLI version 3.5.0 which may have some improvements 更新:您还可以尝试使用最新的Ionic CLI版本3.5.0,它可能会有一些改进

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM