Skip to content
Latchkey

npm prune: Usage, Options & Common Errors

Remove extraneous packages from node_modules.

npm prune deletes installed packages that are not declared in package.json - useful for trimming production images after a full install.

What it does

Removes node_modules entries that are not listed as dependencies. With --omit=dev it also removes devDependencies, leaving only what production needs. With --dry-run it reports what it would remove.

Common usage

Terminal
npm prune                   # remove extraneous packages
npm prune --omit=dev        # strip devDependencies for prod
npm prune --dry-run         # preview removals

Common CI pattern: slim the production image

A Docker image ships dev tooling because the build did a full install. After building, prune dev dependencies so the runtime layer carries only production deps - or use npm ci --omit=dev directly when no build-time dev deps are needed.

Dockerfile
RUN npm ci && npm run build && npm prune --omit=dev

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →