Skip to content
Latchkey

npm dedupe: Flatten Duplicate Deps

npm dedupe reduces duplicate packages by hoisting shared versions.

Duplicate copies of a library cause subtle bugs (two React instances, failed instanceof checks). dedupe collapses them where versions allow.

Common usage

  • npm dedupe - flatten the tree
  • --dry-run - preview
  • npm ls <pkg> - confirm duplicates first

Example in CI

Check then dedupe.

shell
npm dedupe --dry-run

In CI

Run dedupe locally and commit the updated lockfile; do not dedupe in the build. It only helps when versions are compatible.

Key takeaways

  • dedupe collapses compatible duplicates.
  • Commit the resulting lockfile.
  • Use npm ls to find duplicates.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →