NodeJs :- 92% chunk asset optimization TerserPlugin FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

NodeJs :- 92% chunk asset optimization TerserPlugin FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

我在 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

尝试在 google 搜索后更新 webpack(特别是 terser 插件)但没有成功,不断出现此错误。

在传递以下节点选项以及其他构建命令后,即

export "NODE_OPTIONS=--max_old_space_size=2000"

堆内存不再不足,问题已解决。

试试这个,对我有用:“ ng serve --sourceMap=false ”

就我而言,我是在 Mac 的基础上构建的。 原因是虽然我有:

ENV NODE_OPTIONS=--max_old_space_size=8192

我的本地 Docker 引擎设置只允许 2GB 内存。 改成8GB后,一切都变快了。

我 运行 遇到一个问题,其中 webpack 配置是 class 而不是普通的 javascript 配置,当垃圾收集 运行 它导致崩溃..