Skip to content
Latchkey

npm prune: Remove Extraneous Packages

npm prune removes installed packages that are no longer declared.

In a Docker build you often install everything to test, then prune dev dependencies before copying node_modules into the runtime image.

Common flags

  • --omit=dev - drop devDependencies
  • --dry-run - preview removals
  • --json - structured output

Example in CI

Slim a production image after building.

shell
npm prune --omit=dev

In CI

Common in multi-stage Docker builds to shrink the final image. Equivalent to a fresh npm ci --omit=dev in many pipelines.

Key takeaways

  • --omit=dev strips dev packages.
  • Useful before copying node_modules to runtime.
  • Preview with --dry-run.

Related guides

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