node.js - webpack package reports javaScript heap out of memory, how to solve it?
滿天的星座
滿天的星座 2017-05-16 13:38:41
0
2
1243
将nodejs从5.1.1升级到6.10.2之后,执行生产环境的打包(`set NODE_ENV=production  && webpack  --config webpack.production.config.js`),控制台报错:“CALL_AND_RETYR_LAST Allocation failed -javascript heap out of memoty”。
![图片描述](/img/bVMNK1)(这是一张图片,为什么上传不了?)
我nodejs版本是6.10.2, npm原本是3.10.X,后台看在stackoverflow上看到有人说把npm更新到最新版就能解决这个问题,npm最后更新到4.5.0。

无论是百度还是stackoverflow,我都找过解决方案(我找到了webpack.cmd,在命令行“node  "%~dp0\node_modules\webpack\bin\webpack.js" %* ”添加 "-max_old_space_size = 2048"参数),并且尝试了,但是没有用,怎么破?
滿天的星座
滿天的星座

reply all(2)
为情所困

Hey, I finally did it myself. In fact, now I find that the idea I started to solve the problem is correct, which is to add "--max_old_space_size" to the node command line. The mistake is that I added it in the wrong place (maybe it doesn't work in my environment?). At first, I referred to the solution provided by segmentfault on a problem where the same weback packaging caused nodejs memory overflow, which was to add it to the global webpack.cmd (the path is: C:UsersAdministratorAppDataRoamingnpmwebpack.cmd), as shown below :

But it was found that it did not work. After executing the command, the memory still overflowed. Then I struggled for a long time, and the next day I searched for the answer again on stackoverflow and found this answer:

So, I changed the npm hook script used for packaging in my production environment to: "set NODE_ENV =production && node --max_old_space_size=2048 node_modules/webpack/bin/webpack.js --config webpack.production.config.js". That is to say, I use local/local webpack instead of globally installed webpack for packaging. The memory overflow problem was solved by adding "--max_old_space_size=2048" to nodejs to expand the memory to 2*1024M=2G.

Peter_Zhu

There is too little evidence to solve the case!

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template