npm uninstall
卸载已安装的依赖包
语法
npm uninstall <package> [--save-dev] [--global]
参数
| 参数 | 说明 | 示例 | 级别 |
|---|---|---|---|
<package> |
卸载指定包 | npm uninstall lodash |
常用 |
-D --save-dev |
从 devDependencies 中移除 | npm uninstall -D jest |
常用 |
-g --global |
卸载全局包 | npm uninstall -g typescript |
常用 |
示例
卸载包
npm uninstall moment
同时从 package.json 和 node_modules 中移除
卸载多个包
npm uninstall lodash underscore
卸载全局包
npm uninstall -g create-react-app
推荐用 npx 代替全局安装
常见错误
npm WARN not installed
包未安装,检查包名拼写
技巧
- npm un 是 npm uninstall 的简写
- 卸载后检查是否有其他包依赖它
- 定期用 npm prune 清理多余的包