webpack打包vue项目CALL_AND_RETRY_LAST Allocation failed
程序员文章站
2024-02-11 11:37:16
...
打包 一个vue.js+electron+webpack项目时,执行yarn run build
之后发现卡住了,然后出现如下异常:
D:\Documents\mimic>yarn run build
yarn run v1.9.4
warning package.json: No license field
$ node .electron-vue/build.js && electron-builder
___ __ __ ___ __
/\_ \ __ /\ \__ ____ /\ \ __ __ __ /\_ \ /\ \
\//\ \ / ,.`\ \ \ ,_\ / ,__\ _______ \ \ \____ /\ \/\ \ /\_\ \//\ \ \_\ \
\_\ \_ /\ __/ \ \ \/ /\__, `\/\______\ \ \ ,. \\ \ \_\ \\/\ \ \_\ \_ /\ ,. \
/\____\\ \____\ \ \ \_ \/\____/\/______/ \ \____/ \ \____/ \ \ \ /\____\\ \____\
\/____/ \/____/ \ \__\ \/___/ \/___/ \/___/ \/_/ \/____/ \/___ /
\/__/
√ building main process
- building renderer process
<--- Last few GCs --->
[53320:000001EABA0D0AD0] 402245 ms: Mark-sweep 1392.1 (1594.8) -> 1392.1 (1595.3) MB, 5883.0 / 0.0 ms allocation failure GC in old space requested
[53320:000001EABA0D0AD0] 408532 ms: Mark-sweep 1392.1 (1595.3) -> 1391.9 (1539.8) MB, 6285.2 / 0.0 ms last resort
[53320:000001EABA0D0AD0] 413294 ms: Mark-sweep 1391.9 (1539.8) -> 1391.9 (1522.8) MB, 4761.0 / 0.0 ms last resort
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 00000019C7029891 <JS Object>
2: _append [D:\Documents\mimic\node_modules\babel-generator\lib\printer.js:~200] [pc=0000001875BF18B2](this=0000021C1BC88F91 <a Generator with map 000001D966F0C181>,str=000003F551CF9491 <String[1]: =>)
3: token [D:\Documents\mimic\node_modules\babel-generator\lib\printer.js:~142] [pc=0000001875BE90E1](this=0000021C1BC88F91 <a Generator with map 000001D966F0C181>,str=000003F551CF9491 <...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
搜索到2个方法:
方法1(对我无效):
打开node_modules/.bin/webpack.cmd文件,在node命令后面加上–max-old-space-size=4096。我试了4096、81922 个参数(硬件内存是足够的),都不行。还是会出现上述报错。
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "%~dp0\..\webpack\bin\webpack.js" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node "--max-old-space-size=8192 %~dp0\..\webpack\bin\webpack.js" %*
)
方法2(对我有效):
在项目的webpage.js文件中直接进行修改,在build的命令中的node后面加上个空格和–max-old-space-size=4096就可以了。参数可以自行设置,大小的单位为m。注意这里的横杠-必须为英文格式,小心弄错为中文格式导致报错。
如原代码为:
"scripts": {
"build": "node .electron-vue/build.js && electron-builder"
},
修改后为:
"scripts": {
"build": "node -max-old-space-size=4096 .electron-vue/build.js && electron-builder"
},
该方法可以解决该报错问题。
推荐阅读
-
webpack打包vue项目CALL_AND_RETRY_LAST Allocation failed
-
如何用webpack4带你实现一个vue的打包的项目
-
解决vue-cli项目webpack打包后iconfont文件路径的问题
-
解决在vue项目中webpack打包后字体不生效的问题
-
使用webpack打包后的vue项目如何正确运行(express)
-
vue和webpack打包项目相对路径修改的方法
-
详解webpack打包vue项目之后生成的dist文件该怎么启动运行
-
Vue项目webpack打包部署到服务器的实例详解
-
vue项目打包webpack体积优化
-
解决vue-cli项目webpack打包后iconfont文件路径的问题