Removing Packages (`npm uninstall` / `pnpm remove`)
Guide to uninstalling dependencies from package.json and node_modules, cleaning orphaned transitive packages, and removing global packages.
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 lodashRemoving Multiple Packages
npm uninstall moment axios jqueryRemoving Global Packages
# npm global removal
npm uninstall -g nodemon
# pnpm global removal
pnpm remove -g nodemonCleaning 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=devWith pnpm:
pnpm pruneRelated Guides
Installing Packages (`npm install` / `pnpm add`)
Complete guide to installing packages, installing specific versions, Git repositories, local tarballs, global packages, and dependency flags.
Updating Packages Safely
Complete guide to updating dependencies with npm update, pnpm update, handling major version breaking changes, and using interactive update CLI tools.