Skip to main content
⚡ OpenDevDocs
Package Managers
programmingpackage-managersGuideBeginner

Removing Packages (`npm uninstall` / `pnpm remove`)

Guide to uninstalling dependencies from package.json and node_modules, cleaning orphaned transitive packages, and removing global packages.

Verified: 2026-09-30
Tested on:npm 10.x, pnpm 9.x
Platforms:
linuxmacoswindows
#remove#uninstall#npm#pnpm

Removing unneeded dependencies keeps bundle sizes lean, prevents security vulnerabilities, and speeds up continuous integration installs.


Uninstalling Project Dependencies

# npm (removes from package.json, package-lock.json, and node_modules)
npm uninstall lodash
# or shorthand:
npm rm lodash

# pnpm
pnpm remove lodash
# or shorthand:
pnpm rm lodash

Removing Multiple Packages

npm uninstall moment axios jquery

Removing Global Packages

# npm global removal
npm uninstall -g nodemon

# pnpm global removal
pnpm remove -g nodemon

Cleaning Transitive Dependencies (npm prune)

Sometimes removing a package leaves unused transitive sub-dependencies in node_modules. Run prune to clean them:

# Removes packages in node_modules not listed in package.json
npm prune

# Prunes devDependencies from node_modules (production preparation)
npm prune --omit=dev

With pnpm:

pnpm prune

On this page