文章

Fixing Node.js 20 GitHub Actions Errors

Github action出错 强制更新node

Fixing Node.js 20 GitHub Actions Errors

The Fix (Update to Node 24): Update your workflow to use the latest version of standard actions.

’’’

1
2
3
4
5
6
steps:
- uses: actions/checkout@v4  # Ensure you are on v4+[[5](https://www.google.com/url?sa=E&q=https%3A%2F%2Fvertexaisearch.cloud.google.com%2Fgrounding-api-redirect%2FAUZIYQHijpuGWVfSwPzSs_fRLhEWk7JAMzmUCNEX8Fw1ZM_qvEl-3DjGFnh58B6_RFJjvRGcJnL2M9Oph87UDFMmHCu-LJbMx0TrYHnSGtge4jr82o3ULefLB4TsjFvLJsFgxMKYZnE6kF8Qcyg4vZwdfA%3D%3D)]
- name: Setup Node
    uses: actions/setup-node@v4
    with:
    node-version: '24' # Change from '20' to '24' '''

先找到工作流文件

一般目录是 .github/workflows ,然后其中会有yml文件 一个或者多个都属正常 然后修改

’’’

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
name: "Build and Deploy"
on:
push:
    branches:
    - main
    - master
    paths-ignore:
    - .gitignore
    - README.md
    - LICENSE

workflow_dispatch:

permissions:
contents: read
pages: write
id-token: write

concurrency:
group: "pages"
cancel-in-progress: true

# 在全局范围添加环境变量,强制所有 JS Action 使用 Node 24 运行
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true

jobs:
build:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout
        uses: actions/checkout@v4
        with:
        fetch-depth: 0

    - name: Setup Pages
        id: pages
        uses: actions/configure-pages@v5 # 升级到 v5

    - name: Setup Ruby
        uses: ruby/setup-ruby@v1
        with:
        ruby-version: 3.3
        bundler-cache: true

    - name: Build site
        run: bundle exec jekyll b -d "_site$"
        env:
        JEKYLL_ENV: "production"

    - name: Test site
        run: |
        bundle exec htmlproofer _site \
            --disable-external \
            --ignore-urls "/^http:\/\/127.0.0.1/,/^http:\/\/0.0.0.0/,/^http:\/\/localhost/"

    - name: Upload site artifact
        uses: actions/upload-pages-artifact@v3 # 确保是 v3,如果报 node 错误,上述 env 会处理
        with:
        path: "_site$"

deploy:
    environment:
    name: github-pages
    url: $
    runs-on: ubuntu-latest
    needs: build
    steps:
    - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v4 # 确保是 v4 '''

如果你的报错是 Unsupported engine(引擎不支持),你需要修改你项目根目录下的 package.json 文件。

’’’

1
2
3
4
5
6
7
{
"name": "your-project",
"version": "1.0.0",
"engines": {
    "node": ">=24" 
}
}

’’’

本文由作者按照 CC BY 4.0 进行授权