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

React开发服务器持续崩溃,报Array buffer分配失败错误求助

React项目本地运行时webpack导致Array buffer分配失败的解决办法

本地搭建React电商练习项目,安装多框架依赖后,运行时服务器持续崩溃,报错如下:

node:internal/buffer:959
    super(bufferOrLength, byteOffset, length);
    ^

RangeError: Array buffer allocation failed
    at new ArrayBuffer (<anonymous>)
    at new Uint8Array (<anonymous>)
    at new FastBuffer (node:internal/buffer:959:5)
    at createUnsafeBuffer (node:internal/buffer:1062:12)
    at Function.allocUnsafeSlow (node:buffer:385:10)
    at new Uint8Array (<anonymous>)
    at new FastBuffer (node:internal/buffer:959:5)
    at createUnsafeBuffer (node:internal/buffer:1062:12)
    at Function.allocUnsafeSlow (node:buffer:385:10)
    at read (C:\Users\HP-PC\Desktop\react\ecom\node_modules\webpack\lib\serialization\FileMiddleware.js:597:32)
    at C:\Users\HP-PC\Desktop\react\ecom\node_modules\webpack\lib\serialization\FileMiddleware.js:657:7
    at C:\Users\HP-PC\Desktop\react\ecom\node_modules\graceful-fs\graceful-fs.js:362:16
    at FSReqCallback.oncomplete (node:fs:188:23)

已尝试卸载重装Node.js,问题未解决。


解决方案:

  • 清理webpack缓存:手动删除项目内node_modules/.cache/webpack目录和根目录的dist文件夹,或执行项目自带的清理脚本(如npm run clean),避免损坏/过大的缓存文件引发内存分配异常。
  • 提升Node.js内存限制:在package.json的启动脚本中添加内存参数,扩大Node可用内存。例如:
    "scripts": {
      "start": "node --max-old-space-size=4096 node_modules/react-scripts/scripts/start.js"
    }
    
    数值可根据自身机器内存调整(如8192代表8G)。
  • 重新安装全部依赖:删除node_modules文件夹、package-lock.json(或yarn.lock)文件,执行npm install修复可能损坏的webpack相关依赖。
  • 排查项目内大文件:检查项目目录是否存在超大文件(如几G的视频、日志),这类文件会导致webpack读取时内存溢出,将其移出项目或在webpack配置中添加忽略规则。
  • 检查webpack配置:若自定义了webpack配置,排查是否存在过度监听文件、不必要的序列化插件等设置,缩小监听范围,关闭非必需插件。

内容的提问来源于stack exchange,提问作者Nuel44

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.10 12:20:34