Prune extraneous 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.
Identifies packages not declared by the project, then removes them from node_modules while preserving declared production and development dependencies.
nodenpmprune
Commands
Identify packages marked extraneous before removing them
npm ls --depth=0Remove extraneous packages without executing lifecycle scripts
npm prune --ignore-scriptsVerification
npm ls --depth=0No direct package is marked extraneous after pruning.
Undo
Not undoable
Undeclared packages and manual changes removed from node_modules cannot be reconstructed from package metadata.
Pitfalls
- Declare intentionally used packages before pruning; relying on undeclared modules makes builds non-reproducible.
- Lifecycle scripts are disabled while pruning; packages that depend on them may need separately reviewed setup.
- Manually edited files under node_modules are removed and should not be treated as source code.