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

Next.js/React项目推GitHub因Webpack缓存文件过大失败,求解决方案

问题:Next.js项目推送到GitHub时因Webpack缓存文件过大失败,如何忽略缓存且不影响Vercel部署?

我正在开发一个Next.js/React项目,想要将其推送到GitHub后部署至Vercel,但执行命令git push -f origin master时,出现以下错误:

remote: warning: File .next/cache/webpack/client-development/1.pack is 51.79 MB; this is larger than GitHub's recommended maximum file size of 50.00 MB
remote: warning: File .next/cache/webpack/client-development/10.pack is 85.61 MB; this is larger 
than GitHub's recommended maximum file size of 50.00 MB
remote: warning: File .next/cache/webpack/client-development/4.pack is 68.47 MB; this is larger than GitHub's recommended maximum file size of 50.00 MB
remote: warning: File build/cache/webpack/client-development/6.pack is 58.71 MB; this is larger than GitHub's recommended maximum file size of 50.00 MB
remote: warning: File .next/cache/webpack/client-development/33.pack is 58.47 MB; this is larger 
than GitHub's recommended maximum file size of 50.00 MB
remote: warning: File .next/cache/webpack/client-development/18.pack is 68.53 MB; this is larger 
than GitHub's recommended maximum file size of 50.00 MB
remote: warning: File .next/cache/webpack/client-production/11.pack is 57.80 MB; this is larger than GitHub's recommended maximum file size of 50.00 MB
remote: warning: File .next/cache/webpack/client-development/36.pack is 70.37 MB; this is larger 
than GitHub's recommended maximum file size of 50.00 MB
remote: warning: File .next/cache/webpack/client-development/16.pack is 51.49 MB; this is larger 
than GitHub's recommended maximum file size of 50.00 MB
remote: error: Trace: 03b58dddd7287425c8208146b851869685188308516370c77e3e662c5153ba87
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File build/cache/webpack/client-development/10.pack is 139.61 MB; this exceeds GitHub's file size limit of 100.00 MB

我已查阅相关资料但未找到解决方案,请问是否有办法忽略Webpack缓存且不影响网站部署?


解决方案

核心逻辑

.next/cache和build/cache是本地构建生成的Webpack缓存文件,完全不需要推送到GitHub。Vercel部署时会基于你的源码重新执行完整构建流程,自动生成这些缓存文件,因此忽略它们不会对部署造成任何影响。

具体步骤

  1. 配置.gitignore忽略缓存文件夹
    在项目根目录的.gitignore文件中(没有就新建一个)添加以下规则:

    # 忽略Next.js的Webpack缓存文件夹
    .next/cache/
    build/cache/
    
  2. 移除已提交到仓库的缓存文件
    执行以下命令,把已经推送到远程仓库的缓存文件从Git版本控制中移除(本地文件会保留,仅删除远程仓库中的对应文件):

    git rm -r --cached .next/cache build/cache
    git commit -m "移除仓库中的大型Webpack缓存文件"
    git push origin master
    
  3. 重新推送代码
    完成上述操作后,再次执行git push origin master即可正常推送,不会再触发文件大小超限的错误。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.15 09:05:28