Fix Vercel build failing on deploy when it works locally (Node version)
The problem
npm run build was clean on my laptop (Node 22) but the deploy failed with:
ReferenceError: File is not defined
at Object.<anonymous> (dist/upload.js:12:24)
File is a global since Node 20; the platform was building on its older default Node 18.
What didn't work
- Clearing
.nextand the build cache and retrying — the build environment still ran the platform's default Node; the cache was never the problem. - Adding
"engines": { "node": ">=22" }to package.json and assuming the host honors it — many platforms ignoreenginesand only warn or don't warn at all. - Pinning dependencies harder — a dependency bump can't fix the runtime API set of the Node binary doing the build.
The fix
One source of truth for the Node version, used by local, CI and the platform:
# .nvmrc (committed to the repo)
22.14.0
# .github/workflows/build-parity.yml
name: build-parity
on: [pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: npm
- run: npm ci
- run: npm run build # CI now fails BEFORE deploy if toolchains drift
Then set the platform's Node version to the same release — on Vercel: Project Settings → General → Node.js Version → 22.x (it does not read .nvmrc or engines for you).
Why it works
The failure is a toolchain mismatch, not a code bug: code using a Node 20+ global cannot compile on Node 18 anywhere. Pinning one version everywhere makes every build reproducible, and the CI job surfaces the drift on the PR instead of at deploy time.