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

使用act运行GitHub Action时提示无法找到yarn可执行文件

解决act运行GitHub Action时找不到yarn的问题

问题根源

act默认使用的ubuntu-latest镜像(nektos/act-environments-ubuntu:latest)没有预装yarn,而GitHub官方的Ubuntu Runner是预装了yarn的,因此本地运行时会出现找不到yarn的错误。

具体解决方法

1. 在Action步骤中主动安装yarn

在actions/checkout步骤后添加安装yarn的步骤,确保后续步骤能调用到yarn:

name: E2E
on: push
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@master
      
      # 添加这一步安装yarn
      - name: Install Yarn globally
        run: npm install -g yarn
      
      - name: Install dependencies cypress
        uses: cypress-io/github-action@v5
        with:
          runTests: false
      
      - run: yarn lint

      - name: Run e2e tests
        uses: cypress-io/github-action@v5
        with:
          install: false
          working-directory: e2e

      - name: Download the build folders
        if: ${{ failure() }}
        uses: actions/upload-artifact@v2
        with:
          name: cypress-videos
          path: videos

2. 指定act使用预装yarn的镜像

运行act时指定GitHub官方风格的runner镜像,这类镜像预装了大部分GitHub Runner自带的工具(包括yarn):

act -P ubuntu-latest=ghcr.io/catthehacker/ubuntu:act-latest

如果不想每次手动加参数,可以在项目根目录创建.actrc文件,写入以下内容:

-P ubuntu-latest=ghcr.io/catthehacker/ubuntu:act-latest

3. 替换yarn为npm(项目兼容的情况下)

如果项目支持用npm替代yarn,直接修改yarn lint为npm run lint,无需额外安装工具:

- run: npm run lint

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.19 15:38:11