返回提示词目录第 1374 页

升级Node.js长期支持版本

梳理项目版本约束与依赖兼容问题,修复升级故障,并输出双版本验证结果和发布回退方案。

完整提示词

<context>
Check the Node.js release schedule for the target: so far only even-numbered majors have become LTS, odd majors are short-lived and should not reach production, and the project has discussed changing its release cadence, so confirm rather than assume. Most Node upgrades break in the same few places. Native addons (bcrypt, sharp, canvas, sqlite3, node-sass and others built with node-gyp) are compiled against one ABI version and fail with "was compiled against a different Node.js version" until reinstalled, and older releases may have no prebuilt binary for the new ABI, so the install falls back to a compiler that CI images lack. Node 17 moved to OpenSSL 3, so old webpack 4 builds fail with `ERR_OSSL_EVP_UNSUPPORTED`; `--openssl-legacy-provider` hides it but the fix is upgrading the bundler. Node 17 also stopped reordering DNS results, so `localhost` can resolve to `::1` first and connections to services listening only on `127.0.0.1` get `ECONNREFUSED` (Node 20 turned on automatic address family selection for `net` connections, which softens this for some clients but not all). Node 18 added a global `fetch` that can clash with polyfills and test mocks. Each major ships a newer npm, which may rewrite the lockfile format. Newer majors also move module loading forward (for example `require()` of ES modules), which changes behaviour for dual packages. Deprecations surface with `--trace-deprecation` and `--throw-deprecation`. The release notes and the deprecations list for every major you skip are the source of truth.
</context>

<task>
Upgrade this project to Node.js {{target_version}}.
{{#notes}}
Notes:
{{notes}}
{{/notes}}

1. Find every place the version is pinned: `engines` in `package.json`, `.nvmrc`, `.node-version`, Volta or asdf config, Dockerfiles, CI matrices, serverless runtime settings and hosting config. Confirm the target is an LTS line and list the majors skipped.
2. List native and binary dependencies (`node-gyp`, prebuilt binaries, postinstall downloads) and check each has a release supporting the target. Flag any that do not.
3. On the target version, do a clean install with the project's package manager, keeping the lockfile format change in its own commit. Record install warnings and failed builds.
4. Run the build and the full test suite with `--trace-deprecation`. Search for the known breakpoints: legacy OpenSSL hashes in build tools, `localhost` connections to IPv4-only services, fetch polyfills and mocks, removed or changed core APIs from each skipped major's notes.
5. Fix the causes in small commits: upgrade the bundler rather than adding `--openssl-legacy-provider`, use explicit addresses where IPv4 is required, remove polyfills the runtime now provides only when every supported version has the feature.
6. Run CI on both the current and the target version until production has moved.
7. Update `engines`, version files, Docker images and CI, and propose a rollout through staging with logs watched for deprecations and native module errors.
</task>

<constraints>
- Do not use legacy flags (`--openssl-legacy-provider`, `--no-experimental-fetch` and the like) as the fix; if one is needed as a stopgap, mark it with the reason and a follow-up.
- Do not recommend a non-LTS release for production.
- Do not delete and regenerate the lockfile with different dependency versions as a side effect; keep version bumps deliberate and listed.
- Only cite breaking changes you confirmed in the release notes or saw fail.

{{> guardrails/verify-before-done}}
{{> guardrails/scope-discipline}}
</constraints>

<output_format>
## Starting point
Current version, majors skipped, where the version is pinned, native dependencies.
## Breaking changes found
Table: area, symptom, cause, fix.
## Changes made
Dependency upgrades, code and config changes, lockfile change.
## Verification
Install, build and test results on both versions; deprecations remaining.
## Rollout
Environments in order, what to watch, rollback.
</output_format>

可替换内容

  • {{target_version}}
  • {{#notes}}
  • {{notes}}
  • {{/notes}}
  • {{> guardrails/verify-before-done}}
  • {{> guardrails/scope-discipline}}

分类与标签

编程开发、运行时升级、依赖兼容、持续集成、发布回退

前往 AI 图片创作