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

GitHub Action中Yarn安装@expo/vector-icons报错求助

问题:GitHub Action中Yarn Install因路径重复报错

GitHub Action的iOS Build PP工作流执行yarn install时失败,报错显示路径/Users/runner/work/myappname/myappname/node_modules/@expo/vector-icons中重复出现myappname。此前工作流正常运行,未修改相关配置,已尝试删除node_modules、清理Yarn缓存等操作,问题仍存在。

报错信息

➤ YN0001: Error: While persisting /Users/runner/.yarn/berry/cache/@expo-vector-icons-npm-14.1.0-9ab4f0997d-10c0.zip/node_modules/@expo/vector-icons/ -> /Users/runner/work/myappname/myappname/node_modules/@expo/vector-icons Unreachable
    at Zi.statImpl (/Users/runner/.cache/node/corepack/v1/yarn/4.5.1/yarn.js:149:202677)
    at /Users/runner/.cache/node/corepack/v1/yarn/4.5.1/yarn.js:149:215318
    at Function.from (<anonymous>)
    at Zi.readdirSync (/Users/runner/.cache/node/corepack/v1/yarn/4.5.1/yarn.js:149:215289)
    at Zi.readdirPromise (/Users/runner/.cache/node/corepack/v1/yarn/4.5.1/yarn.js:149:214553)
    at makeCallPromise.requireSubpath (/Users/runner/.cache/node/corepack/v1/yarn/4.5.1/yarn.js:9:29795)
    at /Users/runner/.cache/node/corepack/v1/yarn/4.5.1/yarn.js:9:31422
    at t.getMountPromise (/Users/runner/.cache/node/corepack/v1/yarn/4.5.1/yarn.js:9:33120)
    at t.makeCallPromise (/Users/runner/.cache/node/corepack/v1/yarn/4.5.1/yarn.js:9:31377)
    at t.readdirPromise (/Users/runner/.cache/node/corepack/v1/yarn/4.5.1/yarn.js:9:29700)

工作流配置

name: iOS Build PP

on:
  workflow_dispatch:

jobs:
  deploy:
    runs-on: macos-15
    environment: testing
    steps:
      - name: List Xcode installations
        run: sudo ls -1 /Applications | grep "Xcode"

      - name: Select Xcode 16.2
        run: sudo xcode-select -s /Applications/Xcode_16.2.app

      - name: Print Xcode version
        run: xcodebuild -version

      - name: Update CocoaPods version
        run: |
          gem install cocoapods
      - name: Print CocoaPods version
        run: |
          pod --version
      - name: Check out Git repository
        uses: actions/checkout@v4.2.1

      - name: Set Node.js version
        uses: actions/setup-node@v4.1.0
        with:
          node-version: 23.0.0

      - name: Enable Corepack
        run: corepack enable

      - name: Prepare Yarn 4.5.1
        run: corepack prepare yarn@4.5.1 --activate

      - name: Print Yarn Config immutable flag value
        run: yarn config get enableImmutableInstalls

      - name: Create env file
        run: |
          echo "${{ secrets.ENV_FILE }}" > .env.development
          echo "${{ secrets.ENV_FILE }}" > .env

      - name: Get yarn cache directory path
        id: yarn-cache-dir-path
        run: echo "::set-output name=dir::$(yarn cache dir)"

      # 无论是否使用yarn缓存均出现相同错误
      - name: Cache node_modules and yarn cache
        uses: actions/cache@v4.2.0
        id: yarn-cache
        with:
          path: |
            node_modules
            .yarn/cache
          key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
          restore-keys: |
            ${{ runner.os }}-yarn-

      - name: Remove node_modules
        run: rm -rf node_modules

      # 我尝试清理缓存文件夹
      - name: Clean Yarn Berry cache
        run: rm -rf .yarn/cache/*

      - name: Clear Yarn cache
        run: yarn cache clean --all

      - name: Install dependencies  
        run: yarn install  
解决方案
  • 修正checkout步骤的路径:GitHub Actions默认检出路径为/Users/runner/work/<repo-name>/<repo-name>,若actions/checkout被意外设置了path参数会导致嵌套。显式指定当前目录避免问题:

    - name: Check out Git repository
      uses: actions/checkout@v4.2.1
      with:
        path: .
    
  • 强制指定Yarn模块目录:通过Yarn配置固定node_modules路径,避免嵌套。在工作流中添加:

    - name: Set Yarn modules folder
      run: yarn config set modulesFolder ./node_modules
    

    或在项目根目录的.yarnrc.yml中添加:

    modulesFolder: ./node_modules
    
  • 调整缓存逻辑:当前工作流先恢复缓存再删除node_modules,逻辑冲突。改为只缓存Yarn全局缓存,移除冗余的删除步骤:

    - name: Cache Yarn global cache
      uses: actions/cache@v4.2.0
      id: yarn-cache
      with:
        path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
        key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
        restore-keys: |
          ${{ runner.os }}-yarn-
    

    同时删除Remove node_modules、Clean Yarn Berry cache、Clear Yarn cache步骤。

  • 切换稳定Node.js版本:Node.js 23为开发版本,可能与Yarn 4.5.1存在兼容性问题,改用LTS版本:

    - name: Set Node.js version
      uses: actions/setup-node@v4.1.0
      with:
        node-version: 20.x
    
  • 检查项目Yarn配置:确认项目根目录的.yarnrc.yml或.yarnrc中无错误的路径配置(如prefix参数)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 08:19:59