install
npm uninstall
Removes a package from node_modules and drops it from the matching section of package.json and the lockfile. Aliases: `remove`, `rm`, `r`, `un`.
npm uninstall <pkg> [<pkg>...] [--save-dev|--global|--no-save] Common flags
| Flag | Purpose |
|---|---|
| --save-dev (-D) | Remove specifically from devDependencies |
| --save-optional (-O) | Remove from optionalDependencies |
| --global (-g) | Uninstall a globally-installed package |
| --no-save | Remove from node_modules but leave package.json unchanged |
Examples
npm uninstall lodash Remove lodash from the project and lockfile
npm rm -D @types/node Alias to remove a devDependency
npm uninstall -g nodemon Remove a globally-installed CLI
Gotcha
If a package appears in multiple dependency sections, npm removes it from all of them unless you pass a specific --save-* flag. After large removals, run `npm install` to prune orphaned nested deps from the tree.
Related commands
npm install
Installs a package (and its dependencies), adding it to package.json and refreshing package-lock.json. Without arguments, installs everything already declared in the current project's package.json.
npm list
Prints the installed dependency tree of the current project (or globally). Aliases: `ls`, `la`, `ll`.
npm why (explain)
Prints the dependency chain(s) that caused a specific package (or version) to be installed. Alias: `why`; invaluable for tracking down duplicate copies or unexpected transitive deps.
npm install --global
Installs a package into the global prefix so its bin scripts are on your PATH system-wide. Global installs live outside any project's node_modules.
npm ci
Performs a clean, deterministic install straight from package-lock.json (or npm-shrinkwrap.json) intended for CI environments. It deletes any existing node_modules and refuses to run if package.json and the lockfile are out of sync.