Github Actions 执行 Node 环境报错

2024-06-17 · 243 chars · 2 min read

今天 github 上一个项目,actions 执行异常了,报错信息如下:

Run actions/setup-node@v2
  with:
    node-version: 14
    always-auth: false
    check-latest: false
    token: ***
Attempting to download 14...
Not found in manifest.  Falling back to download directly from Node
Error: Unable to find Node version '14' for platform darwin and architecture arm64.

这个项目好多年没有动过了,基本就是 Dependabot 帮忙定期升级下依赖。

这次异常是在 node 14 + macos latest(14.5)下发生的,项目的 actions 配置如下:

name: unittest

on: push

jobs:
  test:
    name: Test on node ${{ matrix.node_version }} and ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        node_version: [14, 18]
        os: [ubuntu-latest, macOS-latest]
    steps:
      - uses: actions/checkout@v2

      - name: Use Node.js ${{ matrix.node_version }}
        uses: actions/setup-node@v2
        with:
          node-version: ${{ matrix.node_version }}

      - name: npm install
        run: npm install

      - name: npm run test
        run: npm run test

根据异常信息和这个 github issue 的描述,添加 architecture: 'x64' 即可,顺便升级下 actions/setup-node@v4

- name: Use Node.js ${{ matrix.node_version }}
  uses: actions/setup-node@v4
  with:
    node-version: ${{ matrix.node_version }}
    architecture: 'x64'

搞定!

赞赏

微信