NodeJs:- 92% 块资产优化 TerserPlugin 致命错误:CALL_AND_RETRY_LAST 分配失败 - JavaScript 堆内存不足
Posted
技术标签:
【中文标题】NodeJs:- 92% 块资产优化 TerserPlugin 致命错误:CALL_AND_RETRY_LAST 分配失败 - JavaScript 堆内存不足【英文标题】:NodeJs :- 92% chunk asset optimization TerserPlugin FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory 【发布时间】:2020-06-08 01:10:06 【问题描述】:我在 react 和使用 storybook 和 webpack 中关注依赖项和大量组件,
"@storybook/react": "5.0.6",
"styled-components": "5.0.1",
"typescript": "3.5",
"webpack": "4.39.3",
"webpack-cli": "3.3.7"
在远程构建故事书时,本地一切正常,但在这一步不断失败,出现此错误:-
16:19:16 <s> [webpack.Progress] 92% chunk asset optimization TerserPlugin
16:21:20
16:21:20 <--- Last few GCs --->
16:21:20
16:21:20 [430:0x3f22bb0] 291204 ms: Mark-sweep 1403.2 (1484.9) -> 1403.2 (1484.9) MB, 1152.6 / 0.0 ms allocation failure GC in old space requested
16:21:20 [430:0x3f22bb0] 292437 ms: Mark-sweep 1403.2 (1484.9) -> 1403.0 (1453.9) MB, 1233.4 / 0.0 ms last resort GC in old space requested
16:21:20 [430:0x3f22bb0] 293968 ms: Mark-sweep 1403.0 (1453.9) -> 1403.0 (1453.9) MB, 1531.0 / 0.0 ms last resort GC in old space requested
16:21:20
16:21:20
16:21:20 <--- JS stacktrace --->
16:21:20
16:21:20 ==== JS stack trace =========================================
16:21:20
16:21:20 Security context: 0x3e34ae9a5879 <JSObject>
16:21:20 1: /* anonymous */ [/home/jenkins/workspace/FlashtoolsUikit-03-Npm-Package-Update-Storybook/node_modules/webpack/node_modules/source-map/lib/source-node.js:~342] [pc=0x18aaeba69706](this=0xc21c728c209 <JSGlobal Object>,chunk=0x19b226eb79a1 <String[2]: >,original=0x1f48ac1ce9 <Object map = 0x3723b1482259>)
16:21:20 2: SourceNode_walk [/home/jenkins/workspace/FlashtoolsUikit-03-Npm-Package-Update...
16:21:20
16:21:20 FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - javascript heap out of memory
16:21:20 1: node::Abort() [node]
16:21:20 2: 0x8c21ec [node]
16:21:20 3: v8::Utils::ReportOOMFailure(char const*, bool) [node]
16:21:20 4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [node]
16:21:20 5: v8::internal::Factory::NewUninitializedFixedArray(int) [node]
16:21:20 6: 0xd4b153 [node]
16:21:20 7: v8::internal::Runtime_GrowArrayElements(int, v8::internal::Object**, v8::internal::Isolate*) [node]
16:21:20 8: 0x18aaeb5042fd
16:21:48 sh: line 1: 420 Aborted (core dumped) npm run build:storybook
16:21:48 npm ERR! code ELIFECYCLE
16:21:48 npm ERR! errno 134
谷歌搜索后尝试更新webpack(专门的terser插件)但没有成功,继续不断收到此错误。
【问题讨论】:
【参考方案1】:在传递以下节点选项以及其他构建命令后,即
export "NODE_OPTIONS=--max_old_space_size=2000"
没有更多的堆内存,问题得到解决。
【讨论】:
【参考方案2】:就我而言,我是在 Mac 上构建的。 原因是虽然我有:
ENV NODE_OPTIONS=--max_old_space_size=8192
我的本地 Docker 引擎设置只允许 2GB 内存。 将其更改为 8GB 后,一切都运行得更快了。
【讨论】:
这对我有用,尽管我只需将我的设置为 4Gb。 FWIW我也尝试更改交换限制无济于事,它必须是内存。【参考方案3】:试试这个,对我有用:“ ng serve --sourceMap=false”
【讨论】:
以上是关于NodeJs:- 92% 块资产优化 TerserPlugin 致命错误:CALL_AND_RETRY_LAST 分配失败 - JavaScript 堆内存不足的主要内容,如果未能解决你的问题,请参考以下文章
vue cil4 nginx terser-webpack-plugin打包优化
vue cil4 nginx terser-webpack-plugin打包优化