npm 中文文档 npm 中文文档
指南
npmjs.com (opens new window)
指南
npmjs.com (opens new window)
  • 快速入门

    • npm 是什么?
    • npm 安装和更新
    • npm 防止权限错误
    • npm package.json 文件
    • npm 安装包
    • npm 更新包
    • npm 卸载包
    • npm 创建 Node.js 模块
    • npm 发布和更新包
    • npm 使用语义化版本
    • npm 使用 Dist-tags 标记包
    • npm 包和模块的了解
  • 命令行
  • 配置 npm

Uninstalling packages and dependencies


If you no longer need to use a package in your code, we recommend uninstalling it and removing it from your project's dependencies.

Uninstalling local packages


Removing a local package from your node_modules directory


To remove a package from your node_modules directory, on the command line, use the uninstall command . Include the scope if the package is scoped.

This uninstalls a package, completely removing everything npm installed on its behalf.

It also removes the package from the dependencies, devDependencies, optionalDependencies, and peerDependencies objects in your package.json.

Further, if you have an npm-shrinkwrap.json or package-lock.json, npm will update those files as well.

Unscoped package


  1. ``` sh
  2. npm uninstall
  3. ```

Scoped package


  1. ``` sh
  2. npm uninstall
  3. ```

Example


  1. ``` sh
  2. npm uninstall lodash
  3. ```

Removing a local package without removing it from package.json


Using the --no-savewill tell npm not to remove the package from your package.json, npm-shrinkwrap.json, or package-lock.jsonfiles.

Example


  1. ``` sh
  2. npm uninstall --no-save lodash
  3. ```

--saveor -Swill tell npm to remove the package from your package.json, npm-shrinkwrap.json, and package-lock.jsonfiles. This is the default, but you may need to use this if you have for instance save=falsein your .npmrcfile.

Confirming local package uninstallation


To confirm that npm uninstallworked correctly, check that the node_modulesdirectory no longer contains a directory for the uninstalled package(s).

Unix system (such as OSX): ls node_modules
Windows systems: dir node_modules

Uninstalling global packages


To uninstall an unscoped global package, on the command line, use the uninstallcommand with the -gflag. Include the scope if the package is scoped.

Unscoped package


  1. ``` sh
  2. npm uninstall -g
  3. ```

Scoped package


  1. ``` sh
  2. npm uninstall -g
  3. ```

Example


For example, to uninstall a package called jshint, run:

  1. ``` sh
  2. npm uninstall -g jshint
  3. ```

Resources


Uninstalling local packages


Uninstalling global packages

Last Updated: 2023-05-15 10:22:02