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

使用GitHub Action+Vercel部署Vite+React+Pnpm项目报错:spawn pnpm ENOENT

解决GitHub Action + Vercel部署Pnpm项目时的spawn pnpm ENOENT错误

问题重现

推送代码触发GitHub Action部署时,出现以下报错:

Run vercel build --prod --token=***
Vercel CLI 28.10.3
Detected `pnpm-lock.yaml` generated by pnpm 7...
Installing dependencies...
Error: spawn pnpm ENOENT
Error: Process completed with exit code 1.

原Action配置如下:

name: Vercel Deployment
env:
  VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
  VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
on:
  push:
    branches:
      - master
jobs:
  Deploy-Production:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: 18.12.1
      - name: Install Vercel CLI
        run: npm install --global vercel@latest
      - name: Pull Vercel Environment Information
        run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}
      - name: Build Project Artifacts
        run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }}
      - name: Deploy Project Artifacts to Vercel
        run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }}

问题原因

GitHub Action默认的ubuntu-latest运行环境未预装pnpm,Vercel CLI检测到项目根目录的pnpm-lock.yaml后,会尝试调用pnpm安装依赖,但系统找不到pnpm命令,因此抛出spawn pnpm ENOENT错误。

解决方案

在Action流程中添加pnpm的安装步骤,有两种推荐方式:

方式1:利用actions/setup-node直接配置pnpm(推荐)

actions/setup-node支持自动安装指定包管理器,会从pnpm-lock.yaml读取对应版本,同时还能配置缓存加速依赖安装:

- uses: actions/setup-node@v3
  with:
    node-version: 18.12.1
    cache: 'pnpm' # 启用pnpm依赖缓存
    package-manager: 'pnpm' # 自动安装pnpm

方式2:手动安装pnpm

通过npm全局安装pnpm,建议指定与项目lock文件匹配的版本(这里是pnpm 7):

- name: Install pnpm
  run: npm install -g pnpm@7

修改后的完整Action配置

name: Vercel Deployment
env:
  VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
  VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
on:
  push:
    branches:
      - master
jobs:
  Deploy-Production:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: 18.12.1
          cache: 'pnpm'
          package-manager: 'pnpm'
      - name: Install Vercel CLI
        run: npm install --global vercel@latest
      - name: Pull Vercel Environment Information
        run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}
      - name: Build Project Artifacts
        run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }}
      - name: Deploy Project Artifacts to Vercel
        run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.06 03:40:19