Uninstall a package dependency

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.

Records the installed version, then removes a direct dependency from node_modules, package.json, and the package lock.

nodenpmuninstall

Parameters

Direct npm package name to remove.

Commands

Record the installed version before removal

npm ls "<package>" --depth=0

Record which dependency section declares the package

npm pkg get dependencies devDependencies optionalDependencies peerDependencies

Remove the package without executing uninstall lifecycle scripts

npm uninstall --ignore-scripts "<package>"

Verification

npm ls "<package>" --depth=0

npm reports that the package is absent from the project root.

Undo

Not undoable

Reinstallation cannot universally recover the prior version, dependency section, or package-local state removed with node_modules.

Pitfalls

  • To recover tracked project state, restore package.json and package-lock.json from version control, then run npm ci --ignore-scripts.
  • Removing a transitive package directly does not remove the parent dependency that requires it.

Related