找不到地方设置 max-old-space-size
[HBuilder] 14:15:54.965 编译器版本:3.4.8(vue3)
[HBuilder] 14:15:54.972 正在编译中...
[HBuilder] 14:15:55.145 当前应用未配置uni统计版本,默认使用1.0版本;建议使用uni统计2.0版本 ,私有部署数据更安全,代码开源可定制。详情:https://uniapp.dcloud.io/uni-stat
[HBuilder] 14:15:55.364 uni-app 有新版本发布,请执行 `npx @dcloudio/uvm@latest alpha` 更新,更新日志详见:https://download1.dcloud.net.cn/hbuilderx/changelog/4.02.2024030621-alpha.html
[HBuilder] 14:15:55.373 vite v2.9.12 building for production...
[HBuilder] 14:15:55.826 Browserslist: caniuse-lite is outdated. Please run:
[HBuilder] 14:15:55.832 npx browserslist@latest --update-db
[HBuilder] 14:15:55.832 Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating
[HBuilder] 14:16:21.573 <--- Last few GCs --->
[HBuilder] 14:16:21.574 [25002:0x7fbf50008000] 26336 ms: Scavenge (reduce) 2037.8 (2078.6) -> 2037.8 (2080.1) MB, 1.7 / 0.0 ms (average mu = 0.371, current mu = 0.218) allocation failure
[HBuilder] 14:16:21.594 [25002:0x7fbf50008000] 26993 ms: Mark-sweep (reduce) 2041.0 (2081.9) -> 2040.4 (2082.5) MB, 466.5 / 0.0 ms (+ 67.6 ms in 14 steps since start of marking, biggest step 6.9 ms, walltime since start of marking 539 ms) (average mu = 0.293, current mu = 0.
[HBuilder] 14:16:21.595 <--- JS stacktrace --->
[HBuilder] 14:16:21.609 FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
[HBuilder] 14:16:21.609 1: 0x103f08205 node::Abort() (.cold.1) [/Applications/HBuilderX.app/Contents/HBuilderX/plugins/node/node]
[HBuilder] 14:16:21.632 2: 0x102c094d9 node::Abort() [/Applications/HBuilderX.app/Contents/HBuilderX/plugins/node/node]
[HBuilder] 14:16:21.640 3: 0x102c0964f node::OnFatalError(char const*, char const*) [/Applications/HBuilderX.app/Contents/HBuilderX/plugins/node/node]
[HBuilder] 14:16:21.641 4: 0x102d7cb07 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/Applications/HBuilderX.app/Contents/HBuilderX/plugins/node/node]
[HBuilder] 14:16:21.649 5: 0x102d7caa3 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/Applications/HBuilderX.app/Contents/HBuilderX/plugins/node/node]
[HBuilder] 14:16:21.649 6: 0x102f20785 v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/Applications/HBuilderX.app/Contents/HBuilderX/plugins/node/node]
[HBuilder] 14:16:21.657 7: 0x102f1f10c v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/Applications/HBuilderX.app/Contents/HBuilderX/plugins/node/node]
[HBuilder] 14:16:21.682 8: 0x102f2b9b0 v8::internal::Heap::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/Applications/HBuilderX.app/Contents/HBuilderX/plugins/node/node]
[HBuilder] 14:16:21.683 9: 0x102f2ba31 v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/Applications/HBuilderX.app/Contents/HBuilderX/plugins/node/node]
[HBuilder] 14:16:21.692 10: 0x102ef8ac7 v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [/Applications/HBuilderX.app/Contents/HBuilderX/plugins/node/node]
[HBuilder] 14:16:21.693 11: 0x1032b05be v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [/Applications/HBuilderX.app/Contents/HBuilderX/plugins/node/node]
[HBuilder] 14:16:21.703 12: 0x103659319 Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_NoBuiltinExit [/Applications/HBuilderX.app/Contents/HBuilderX/plugins/node/node]
4 个回复
tatan
您好,请问解决了吗?
aspack001 - 老程序猿
我也碰到过,我把sourceMap的开关去掉后就好了。估计是生成sourceMap的时候特别占资源。
应该有有设置webpack打包内存大小的选项的地方
aspack001 - 老程序猿
在windows中添加环境变量NODE_OPTIONS 值为 --max-old-space-size=4096
试试
当你在使用 Webpack 进行打包时遇到 "JavaScript heap out of memory" 错误,这通常意味着 Node.js 的内存分配超出了默认限制。以下是一些解决这个问题的步骤和方法:
1. 增加 Node.js 的内存限制
Webpack 运行在 Node.js 环境中,可以通过增加 Node.js 的内存限制来解决这个问题。
使用
--max-old-space-size
参数:你可以在运行 Webpack 的命令中添加这个参数来增加内存限制。例如:
这里
4096
是以 MB 为单位的内存限制,你可以根据需要调整这个值。2. 优化 Webpack 配置
使用
SplitChunksPlugin
:分割代码可以减少单个 bundle 的体积,降低内存使用。
启用
TerserPlugin
:压缩代码可以减少内存使用。
3. 调整 Babel 配置
如果你在使用 Babel 进行转译,可以优化 Babel 配置以减少内存使用:
使用
babel-loader
的缓存:4. 清理不必要的依赖
删除未使用的代码和依赖:
使用工具如
webpack-bundle-analyzer
来分析你的 bundle,找出哪些模块占用了大量空间。5. 增加系统内存
如果以上方法都不能解决问题,考虑在开发环境中使用更高配置的机器,或者在 CI/CD 环境中增加资源。
6. 使用
happy-pack
HappyPack 可以并行处理 loader,减少内存使用。
总结
内存问题在 Webpack 打包过程中并不少见,通过上述步骤,你应该能够有效地解决或缓解 "JavaScript heap out of memory" 错误。记住,根据你的项目具体情况,可能需要尝试几种方法的组合来找到最佳解决方案。
aspack001 - 老程序猿
找到办法了,在运行配置里把这个node参数调大