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

GitHub Actions Node.js工作流缓存依赖报错:路径无法解析

解决GitHub Actions Node.js工作流的依赖缓存报错问题

你遇到的Error: Some specified paths were not resolved, unable to cache dependencies报错,核心原因是actions/setup-node@v4中cache-dependency-path参数的多路径写法错误——不能用逗号分隔多个路径,YAML语法要求用数组格式(多行或方括号包裹)来指定多个依赖文件路径。

修正后的工作流配置

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [22.x]
    steps:
    - uses: actions/checkout@v4
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v4
      with:
        node-version: ${{ matrix.node-version }}
        cache: 'npm'
        # 改用YAML数组格式指定多个依赖文件路径
        cache-dependency-path:
          - frontend/package-lock.json
          - backend/package-lock.json
        
    - run: npm run ci:frontend
    - run: npm run ci:backend

    - run: npm run build --if-present --prefix frontend
    - run: npm run build --if-present --prefix backend

    - run: npm run test:backend --if-present
    - run: npm run test:frontend --if-present

补充说明

  1. 修正后的cache-dependency-path会分别识别两个子目录的package-lock.json,生成对应缓存键,分别缓存frontend/node_modules和backend/node_modules目录。
  2. 你根目录package.json中的ci:frontend、ci:backend脚本已经通过--prefix指定了子目录,执行时会自动在对应目录完成依赖安装,配合修正后的缓存配置即可正常命中缓存。

额外排查点

  • 确认frontend/package-lock.json和backend/package-lock.json已提交到仓库,未被.gitignore忽略;
  • 保持actions/setup-node版本为v4,不同版本的参数格式存在差异。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 03:43:15