npm lockfile version 2 automatic upgrade lacks rollback mechanism
0 reputation · 29 Sept 2021, 10:20 UTC
Goal
Enable safe reversion to a version 1 lockfile after npm automatically upgrades the schema during npm install.
Constraints and uncertainty
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.
Questions
- Is there any supported workflow or hidden configuration that allows a deterministic downgrade from a version 2 lockfile to a valid version 1 lockfile without relying on external backups?
- What is the expected behavior when a CI job fails after an automatic lockfile upgrade—should the pipeline treat the upgraded lockfile as a permanent artifact or as a transient failure that can be rolled back?
- Does the open RFC propose a specific rollback mechanism (e.g., automatic backup,
--lockfile-versionflag, ornpm lockfile revertcommand), and what is the timeline for implementation?