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

Vercel部署Next.js应用遇依赖与编译错误,求助解决

Next.js 部署至 Vercel 失败的问题与解决建议

本地执行yarn run dev和yarn run build均正常,但Vercel部署时出现构建失败,核心错误日志如下:

The cli flag --force was set. Skipping build cache download.
Cloning completed: 687.734ms
Running "vercel build"
Vercel CLI 28.4.17
Installing dependencies...
yarn install v1.22.17
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
[1/4] Resolving packages...
[2/4] Fetching packages...
error Command failed.
Exit code: 128
Command: git
Arguments: ls-remote --tags --heads ssh://git@github.com/ethereumjs/ethereumjs-abi.git
Directory: /vercel/path0
Output:
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
yarn run v1.22.17
$ next build
info  - Loaded env from /vercel/path0/.env
Attention: Next.js now collects completely anonymous telemetry regarding usage.
This information is used to shape Next.js' roadmap and prioritize features.
You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
https://nextjs.org/telemetry
info  - Linting and checking validity of types...
error - ESLint must be installed in order to run during builds: yarn add --dev eslint
info  - Creating an optimized production build...
info  - Disabled SWC as replacement for Babel because of custom Babel configuration ".babelrc" https://nextjs.org/docs/messages/swc-disabled
info  - Using external babel configuration from /vercel/path0/.babelrc
Failed to compile.
../../usr/local/share/.config/yarn/global/node_modules/next/dist/pages/_document.js
Error: Cannot find module '@babel/preset-react'
# 省略重复的错误堆栈信息
> Build failed because of webpack errors
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Error: Command "yarn run build" exited with 1

解决步骤

  • 清理混合包管理器锁文件:删除项目根目录的package-lock.json,仅保留yarn.lock,避免依赖解析冲突
  • 替换SSH依赖地址为HTTPS:检查package.json中的依赖,将ssh://git@github.com/ethereumjs/ethereumjs-abi.git这类SSH协议的依赖地址替换为HTTPS格式(https://github.com/ethereumjs/ethereumjs-abi.git),Vercel构建环境无SSH密钥权限,无法拉取SSH协议的仓库
  • 安装缺失的开发依赖:
    • 执行yarn add --dev eslint安装ESLint
    • 执行yarn add --dev @babel/preset-react @babel/core安装Babel预设依赖
  • 确认Vercel构建配置:进入Vercel项目设置,验证构建命令为yarn run build,安装命令为yarn install,且环境变量与本地一致
  • 清除Vercel构建缓存:在Vercel项目的构建日志页面,点击"Clear Build Cache"后重新触发构建

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.13 11:20:33