node-version-upgrade
Skill1 starsChanged 7 months agoMITView on GitHub
Upgrade Node.js (16 → 18 → 20 → 22) — what breaks, what improves, ESM transitions, dependency compatibility, Docker base image swaps, CI matrix updates. Use when a Node version is going EOL or you want native fetch/test runner. Covers Node 16 EOL (2023), 18 EOL (2025), 20 LTS, 22 LTS.
- Reads credentials
- Installs packages
In this repository50 other files it gives its agents.
- algolia-searchSkill
- audit-tautological-testsSkill
- blame-archaeologySkill
- brevo-emailSkill
- bun-runtimeSkill
- clerk-authSkill
- cloudflare-workersSkill
- dbt-data-modelingSkill
- explain-this-diffSkill
- extract-skill-from-sessionSkill
- fastapi-productionSkill
- find-dead-codeSkill
- find-real-bugSkill
- gdpr-dpiaSkill
- github-actions-ciSkill
- graphql-relaySkill
- grpc-servicesSkill
- hipaa-auditSkill
- india-dpdp-actSkill
- java-8-to-21Skill
- jest-to-vitestSkill
- kubernetes-helmSkill
- mongo-to-postgresSkill
- nextjs-pages-to-appSkill
- opentelemetry-instrumentSkill
- pci-dss-checklistSkill
- plan-the-rollbackSkill
- python-2-to-3Skill
- razorpay-integrationSkill
- react-native-expoSkill
- scaffold-cli-toolSkill
- scaffold-fullstack-appSkill
- scaffold-go-microserviceSkill
- scaffold-new-appSkill
- scaffold-saas-starterSkill
- sentry-monitoringSkill
- shrink-this-prSkill
- soc2-evidenceSkill
- spec-from-conversationSkill
- stripe-integrationSkill
- supabase-backendSkill
- terraform-patternsSkill
- threat-modeling-strideSkill
- triage-stack-traceSkill
- wcag-accessibility-auditSkill
- webpack-to-viteSkill
- write-adrSkill
- write-commit-messageSkill
- write-pr-descriptionSkill
- write-runbookSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 2 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 91
Use -slim (Debian, smaller) or -alpine (musl, tiniest, sometimes incompatible with native modules) — *not* node:22 (full Debian, fat).
- Distinctive: line 102
Test against the *next* LTS too if you can — catches issues before forced upgrade.
- Very specific: line 160
If you can't migrate yet, the require(esm) flag in Node 22 lets some ESM libs load from CJS.
- Very specific: line 179
If you used node-fetch Response shape extensions (.buffer()), they map to arrayBuffer() in native fetch.
- Distinctive: line 203
Fork-rolling-your-own polyfills: instead of using a maintained one — eternal maintenance.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Upgrade Node.js
Node has a 6-month release cadence and a clear LTS policy. Falling behind is technical debt that compounds with each missed version. This skill is the upgrade path with concrete fixes for the breakages you'll hit.
When to use
- Current Node version is past or near EOL.
- Want native
fetch,test,--watch,--env-file. - Dependency requires a newer Node (e.g. Vite 5 dropped Node 16).
- Cleaning up workarounds that pre-date a feature now in core (
node-fetch,dotenv, etc).
When NOT to use
- Two upgrades back-to-back (16 → 22) on a large app — do 16 → 18 → 20 → 22 incrementally.
- Frozen environment (regulated, can't deploy without recertification) — coordinate with platform team.
EOL dates (the calendar)
| Node | LTS start | EOL |
| 16 | Oct 2021 | Sep 2023 (past EOL) |
| 18 | Oct 2022 | Apr 2025 (past EOL) |
| 20 | Oct 2023 | Apr 2026 |
| 22 | Oct 2024 | Apr 2027 |
| 24 | Oct 2025 | Apr 2028 |
Rule: target the latest active LTS. As of this skill's writing, that's 22.
What changed at each major
16 → 18
| Change | Impact |
Built-in fetch (Undici) | Drop node-fetch. |
Built-in node:test | Drop mocha for many cases (or migrate to vitest). |
| OpenSSL 3 | Some legacy crypto patterns fail (EVP_DecodeUpdate deprecation). Set --openssl-legacy-provider as escape hatch. |
esModuleInterop interaction | TS 4.x compatibility — may need TS bump. |
Common breakage: node-fetch@2 is CJS, doesn't tree-shake; node-fetch@3 is ESM-only (forces ESM transition). Replacing with native fetch removes the issue.
18 → 20
| Change | Impact |
--watch mode | Drop nodemon for simple cases. |
Stable node:test | Drop test runners for libraries. |
| V8 update | Mild perf changes. |
URL parser stricter | Code that relied on lax parsing fails. |
| Permission model (experimental) | New flag --experimental-permission. |
Common breakage: URL constructor used to coerce malformed inputs; now throws. Audit URL parsing in user-input paths.
20 → 22
| Change | Impact |
require(esm) (experimental in 22) | Can require() ESM modules. Big for slow ESM migrations. |
| Built-in WebSocket | Drop ws for client use cases. |
| V8 12 | Improved perf, especially regex. |
--env-file=.env is stable | Drop dotenv for simple loads. |
glob() built-in | Drop glob package. |
Less breaking than 18→20. Mostly additive features.
The upgrade workflow
1. Read the migration guide for each version
The Node project publishes migration guides. Read them. Skim the deprecations.
2. Update engines in package.json
{ "engines": { "node": ">=20.0.0 <23.0.0" } }This warns devs and CI on mismatch. Some PaaS providers (Vercel, Railway) read this for runtime selection.
3. Bump the Docker base image
FROM node:22-slim AS deps # was 18-slimUse -slim (Debian, smaller) or -alpine (musl, tiniest, sometimes incompatible with native modules) — not node:22 (full Debian, fat).
4. Update CI matrix
# .github/workflows/ci.yml
strategy:
matrix:
node: [20, 22] # drop olderTest against the next LTS too if you can — catches issues before forced upgrade.
5. Run tests on each target version locally
nvm use 22
pnpm install
pnpm test
pnpm buildTrack what fails. Tests, not just type-checks.
6. Audit deprecation warnings
node --trace-deprecation src/index.js 2>&1 | grep -i deprecatEven if your tests pass, warnings that emit on every request are a sign you'll break next version.
7. Audit dependencies for compatibility
pnpm install
# Read peerDependencies warnings
# Check changelogs for major depsCommon: prisma, @nestjs/*, @aws-sdk/* need bumping. Pin known-good versions before upgrading.
8. Audit native modules
pnpm rebuild
# Failures here = native module needs prebuilt or rebuild for Node 22bcrypt, sharp, better-sqlite3, node-gyp-built modules can break. Often a version bump fixes; sometimes need to migrate (e.g. bcrypt → bcryptjs for portability).
9. Handle ESM if not already
Node 22 + modern deps push you toward ESM. Many libraries are now ESM-only:
{ "type": "module" }This switches your project to ESM. Consequences:
requireno longer works — convert toimport.- File extensions in imports become required (
./foo.js, not./foo). __dirname/__filenameneed polyfills:import { fileURLToPath } from "node:url"; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename);
If you can't migrate yet, the require(esm) flag in Node 22 lets some ESM libs load from CJS. But ESM is the direction.
10. Deploy progressively
- Local dev → Staging → Canary 5% → Full rollout.
- Watch error rate on canary for 24h before full rollout.
- Have a rollback plan (see
plan-the-rollback) — usually means redeploying the previous container image.
Native fetch migration (the most common cleanup)
// Old
const fetch = require("node-fetch");
const res = await fetch(url);
// New
const res = await fetch(url); // fetch is globalIf you used node-fetch Response shape extensions (.buffer()), they map to arrayBuffer() in native fetch. import { Headers, Request, Response } from undici if you need explicit imports.
Common breakages
| Symptom | Cause | Fix |
error:0308010C:digital envelope routines::unsupported | OpenSSL 3 strict mode | NODE_OPTIONS=--openssl-legacy-provider (escape) or update crypto |
Cannot find module './foo' | ESM requires .js extension | Add extensions to imports |
Cannot use import statement outside a module | CJS file using ESM syntax | Add "type": "module" or rename .mjs |
require is not defined in ES module scope | ESM context | Use import; or import.meta polyfill for require |
Failed to load native binding | Native module not rebuilt | pnpm rebuild or bump the dep |
URL constructor: <bad-url> is not a valid URL | Stricter URL parser | Validate input before passing |
Anti-patterns
- Skipping LTS versions — 16 → 22 directly is harder than 16 → 18 → 20 → 22.
- Upgrading Node and major deps in one PR — too many variables. Upgrade Node first, then deps.
- Pinning
engines: "*"— defeats the purpose. Pin a real range. - No CI matrix on the new version — forced upgrade reveals unknown breakages.
- Ignoring deprecation warnings — they become errors next major.
--openssl-legacy-provideras a long-term solution — buys time only; fix the underlying crypto.- Production canary skipped — Node upgrades have surprised every team that didn't canary.
- Using
nvm-windowsin CI — flaky. Useactions/setup-nodedirectly. - Native modules without explicit version pin — implicit upgrades break unpredictably.
- Fork-rolling-your-own polyfills instead of using a maintained one — eternal maintenance.
Verify it worked
node -vmatches the target version on every developer machine and in CI.package.jsonengines.nodeis set to a real range.- Docker base image bumped; image rebuilds cleanly.
- CI runs tests against target version (and ideally also +1 LTS).
node --trace-deprecationshows no warnings from your code.pnpm install && pnpm rebuildis clean — no native module failures.- All tests pass.
- Production canary at 5% for 24h shows flat error rate vs. baseline.
node-fetch,node-test,dotenv(if not used for advanced features),globare removed where native equivalents replace them.- Old Node version base images are removed from CI/prod artifacts (no fallback).
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

