You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Electron/electron-builder运行与构建时堆内存耗尽问题求助

Electron + React + Webpack 堆内存耗尽问题

运行和构建集成Webpack的React Electron应用时遭遇堆内存耗尽问题,近期出现且与代码变更无关,已阻碍应用打包发布。单独运行React应用可正常构建运行,但执行electron .时React应用无法渲染,输出日志如下:

24  Electron Framework                  0x000000010ace7840 _ZN2v88internal20SetupIsolateDelegate9SetupHeapEPNS0_4HeapE + 2396044
25  Electron Framework                  0x000000010ace3bc0 _ZN2v88internal20SetupIsolateDelegate9SetupHeapEPNS0_4HeapE + 2380556
26  Electron Framework                  0x000000010ac91b6c _ZN2v88internal20SetupIsolateDelegate9SetupHeapEPNS0_4HeapE + 2044600
27  Electron Framework                  0x000000010ac91900 _ZN2v88internal20SetupIsolateDelegate9SetupHeapEPNS0_4HeapE + 2043980
28  Electron Framework                  0x000000010a4d9840 ElectronInitializeICUandStartNode + 5735672
29  Electron Framework                  0x000000010a4d9cec ElectronInitializeICUandStartNode + 5736868
30  Electron Framework                  0x0000000109f6130c ElectronMain + 116
31  Electron                            0x00000001028371dc Electron + 12764
32  dyld                                0x00000001a637fe50 start + 2544

首次遇到该问题是执行electron-builder -mw进行发布构建时,输出类似日志并出现明确错误:

<--- Last few GCs --->

[2820:0x150008000]    50798 ms: Scavenge 8109.9 (8212.4) -> 8109.6 (8223.2) MB, 6.9 / 0.0 ms  (average mu = 0.356, current mu = 0.249) allocation failure 
[2820:0x150008000]    50823 ms: Scavenge 8116.6 (8223.2) -> 8117.4 (8224.2) MB, 12.0 / 0.0 ms  (average mu = 0.356, current mu = 0.249) allocation failure 
[2820:0x150008000]    52552 ms: Scavenge 8117.4 (8224.2) -> 8116.6 (8247.2) MB, 1728.2 / 0.0 ms  (average mu = 0.356, current mu = 0.249) allocation failure 


<--- JS stacktrace --->

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
 1: 0x10481352c node::Abort() [/Users/jacobmacweb/.nvm/versions/node/v16.20.0/bin/node]
 2: 0x10481371c node::ModifyCodeGenerationFromStrings(v8::Local<v8::Context>, v8::Local<v8::Value>, bool) [/Users/jacobmacweb/.nvm/versions/node/v16.20.0/bin/node]

已尝试的解决方案

  • 设置NODE_OPTIONS='--max-old-space-size=8192'和NODE_OPTIONS='--max-old-space-size=16384',但参数未生效,问题依旧。此前相同命令已正常执行过百次。

环境信息

  • Apple Macbook M2 Pro
  • Node.js 16.20(使用nvm管理)
  • Electron ^11.5.0
  • Electron-builder ^22.11.7

如需其他信息,可随时提供。

内容的提问来源于stack exchange,提问作者Jacob MacKenzie-Websdale

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 16:15:03