npm lockfile version 2 automatic upgrade lacks rollback mechanism
0 reputation · 29 Sept 2021, 10:20 UTC
0 reputation · 29 Sept 2021, 10:20 UTC
Enable safe reversion to a version 1 lockfile after npm automatically upgrades the schema during npm install.
When npm (v7–v10) encounters a version 1 lockfile, it upgrades the file in place to version 2 without creating a backup copy. No CLI flag or configuration option exists to force a downgrade back to version 1, and manually editing the lockfileVersion field often produces an invalid lockfile that npm either rejects or rewrites to version 2. In CI pipelines that generate lockfiles on the fly, a failed install can leave the repository with an incompatible version 2 lockfile that blocks subsequent builds, and cached lockfiles may perpetuate the upgraded schema even after source code is reverted. The npm documentation treats version 2 as opt‑in via lockfileVersion but does not describe any rollback procedure, and an open RFC indicates the rollback safety feature remains an unresolved decision.
--lockfile-version flag, or npm lockfile revert command), and what is the timeline for implementation?There is no supported native npm command, hidden configuration, or CLI flag that allows a deterministic downgrade from a version‑2 lockfile back to version‑1.
package-lock.json to version‑2 during npm install.lockfileVersion field produces an invalid lockfile that npm rejects or rewrites.--lockfile-version flag or npm lockfile revert command exists in any released npm version.The upgrade is designed as a forward‑only migration; version‑2 adds metadata (e.g., resolved integrity, package‑name normalization) that cannot be losslessly mapped back to the version‑1 format without re‑resolving the dependency tree.
git checkout package-lock.json# Example using nvm to switch to Node 14 (bundles npm 6)
nvm install 14
nvm use 14
npm installgrep lockfileVersion package-lock.jsonDoes your CI pipeline run npm install or npm ci? The answer changes whether you should treat the upgraded lockfile as a transient failure (npm ci will fail) or allow it to persist (npm install will keep the upgraded file unless you intervene).
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.