Deduplicate installed dependencies
Medium risk
What do risk levels mean?
- Read-only
- Inspects state without changing anything.
- Low risk
- Reversible with a routine follow-up command.
- Medium risk
- Changes state; undo path documented.
- Destructive
- Deletes or overwrites; confirmation required.
Inspects the dependency tree, then moves compatible packages higher in the tree to reduce duplicate installations and update the lockfile as needed.
nodenpmdeduplicate
Commands
Inspect the dependency tree before changing its layout
npm ls --allConsolidate compatible versions without executing lifecycle scripts
npm dedupe --ignore-scriptsVerification
npm find-dupesnpm reports no further compatible deduplication changes, or lists remaining opportunities.
Undo
Restore the tracked dependency layout from the previous lockfile
git restore package-lock.jsonRecreate node_modules without executing lifecycle scripts
npm ci --ignore-scriptsPitfalls
- The undo steps require package-lock.json to be tracked in Git with the desired prior state.
- Lifecycle scripts are disabled during deduplication and recovery; packages that depend on them may need separately reviewed setup.
- Run the project test suite because a flatter dependency tree can expose undeclared dependency assumptions.