Uninstall npm packages cleanly
Remove local or global npm dependencies, review manifest and lockfile changes, and understand why shared transitive packages may remain.
Run npm uninstall package-name in the consuming project. With npm's normal save behavior, it removes the dependency declaration and updates the installed tree and lockfile.
npm uninstall lodash
npm uninstall jest
npm uninstall lodash moment dayjs
npm uninstall --global typescript
The package name is enough when removing a development dependency; a separate --save-dev flag is not required to find its declaration. Check project configuration if save behavior has been customized. --no-save deliberately avoids updating the manifest and lockfile, so it is unsuitable for a permanent dependency removal.
Review the change
Search source code, tests, configuration, and npm scripts for remaining uses. Then inspect the dependency tree:
npm ls --depth=0
npm ls lodash --all
A removed direct dependency may remain somewhere in node_modules because another package still needs it. That is expected. Conversely, an undeclared import might continue working accidentally because a hoisted transitive copy remains; remove the import rather than relying on that layout.
Commit the manifest and lockfile changes together, and run the affected tests and build. npm prune is not normally required after a successful uninstall. Use it when diagnosing genuinely extraneous packages, preferably inspecting npm prune --dry-run first.
Distinguish removal from other maintenance
| Goal | Appropriate operation |
|---|---|
| Remove a declared project dependency | npm uninstall package-name |
| Remove a global package from the active prefix | npm uninstall --global package-name |
| Recreate a locked project installation | npm ci with a consistent lockfile |
| Remove extraneous installed packages | npm prune |
| Check npm's cache integrity | npm cache verify |
Clearing the cache does not uninstall project dependencies and is not a routine uninstall step. Manually deleting a package directory does not update dependency declarations; the next install can restore it.
For npm workspaces, target the workspace that declares the dependency, for example npm uninstall lodash --workspace=web, using the actual workspace name. Removing it only from the repository root does not remove a separate workspace declaration.
Global tools belong to the active npm prefix. If a command still exists after uninstalling it, inspect its resolved path: another Node installation, version-manager environment, shell shim, or unrelated package may provide it. Avoid deleting system directories just because the command name is familiar.
References
Contact us
Join the community
to join the community
Try Guance
Start online and pay only for what you use.
Get startedChoose a Guance plan