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

Vercel部署Vite+Vue项目报错:npm run build exited with 126

Vercel部署Vue+Vite项目时出现Permission denied错误的解决办法

我用Vite+Vue.js开发的项目推到GitHub后,部署到Vercel时触发以下错误:

[09:02:23.126] Running build in San Francisco, USA (West) – sfo1
[09:02:23.266] Cloning github.com/Zein-MB/Age-calulator-app (Branch: master, Commit: 547a770)
[09:02:23.281] Skipping build cache, deployment was triggered without cache.
[09:02:24.636] Cloning completed: 1.369s
[09:02:25.050] Running "vercel build"
[09:02:25.713] Vercel CLI 32.1.0
[09:02:26.411] Installing dependencies...
[09:02:27.132]
[09:02:27.133] up to date in 254ms
[09:02:27.133]
[09:02:27.133] 3 packages are looking for funding
[09:02:27.133] run npm fund for details
[09:02:27.145] Detected package-lock.json generated by npm 7+...
[09:02:27.145] Running "npm run build"
[09:02:27.546]
[09:02:27.546] > age-calculator-app@0.0.0 build
[09:02:27.546] > vite build
[09:02:27.546]
[09:02:27.555] sh: /vercel/path0/node_modules/.bin/vite: Permission denied
[09:02:27.576] Error: Command "npm run build" exited with 126

以下是几种可行的解决方法:

  • 清理仓库中的node_modules
    确保本地node_modules没有被提交到GitHub,Vercel需要自行安装依赖。如果之前误提交,执行以下命令修复:

    git rm -r --cached node_modules
    git commit -m "移除仓库中的node_modules"
    git push
    

    之后重新触发Vercel部署。

  • 修改build命令为npx调用
    直接用npx执行vite,绕过本地node_modules的权限限制:

    "scripts": {
      "build": "npx vite build"
    }
    

    提交修改后重新部署。

  • 强制Vercel重新安装依赖
    在Vercel项目的部署设置中,找到「Build & Development Settings」,勾选「Skip Cache」;或者手动触发部署时选择「Clear cache and deploy」,让Vercel完全重新安装所有依赖,避免缓存导致的权限异常。

  • 切换包管理器
    如果npm安装存在权限问题,尝试改用yarn或pnpm:

    1. 删除本地的package-lock.json
    2. 执行yarn install生成yarn.lock,或pnpm install生成pnpm-lock.yaml
    3. 将新的lock文件提交到GitHub,Vercel会自动检测并使用对应包管理器安装依赖。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.11 22:41:27