Introduction
When attempting to deploy a Vite + React project to Firebase Hosting using GitHub Actions, I encountered a build failure.
After investigating, I discovered the cause was an outdated Node.js version.
I'm documenting this for anyone who runs into the same error.
The Error I Actually Encountered
You are using Node.js 18.20.8. Vite requires Node.js version 20.19+ or 22.12+. Please upgrade your Node.js version.
[vite:asset] Could not load /vite.svg (imported by src/App.tsx): crypto.hash is not a function
GitHub Actions was using Node.js 18
Vite v7 requires Node.js 20.19+ or 22.12+
This caused the build to fail
Solution
1. Upgrade Node.js Version
Specify Node.js version 22 in the CI/CD configuration file.
- name: Setup Node.js
  uses: actions/setup-node@v3
  with:
    node-version: 22
2. Run npm install cleanly
- name: Install dependencies
  run: npm ci
Reference: Post-fix configuration in GitHub Actions
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v3
      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 22
      - name: Install dependencies
        run: npm ci
      - name: Run build
        run: npm run build
Summary
Vite v7 does not work with Node.js 18
GitHub Actions may use an older Node.js version by default
Simply upgrading Node.js to 20 or higher resolves the issue
    
Top comments (0)