如果你不再需要在代码中使用包,我们建议将其卸载并将其从项目的依赖中删除。

¥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

从 node_modules 目录中删除本地包

¥Removing a local package from your node_modules directory

要从 node_modules 目录中删除包,请在命令行上使用 uninstall 命令。如果包是范围的,则包括范围。

¥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.

这将卸载一个包,完全删除代表它安装的所有 npm。

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

它还会从 package.json 中的 dependencies、devDependencies、optionalDependencies 和 peerDependencies 对象中删除包。

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

此外,如果你有 npm-shrinkwrap.json 或 package-lock.json,npm 也会更新这些文件。

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

无范围的包

¥Unscoped package

npm uninstall <package_name>

范围包

¥Scoped package

npm uninstall <@scope/package_name>

示例

¥Example

npm uninstall lodash

删除本地包而不从 package.json 中删除它

¥Removing a local package without removing it from package.json

使用 --no-save 会告诉 npm 不要从你的 package.jsonnpm-shrinkwrap.jsonpackage-lock.json 文件中删除包。

¥Using the --no-save will tell npm not to remove the package from your package.json, npm-shrinkwrap.json, or package-lock.json files.

示例

¥Example

npm uninstall --no-save lodash

--save-S 将告诉 npm 从你的 package.jsonnpm-shrinkwrap.jsonpackage-lock.json 文件中删除该包。这是默认设置,但如果你的 .npmrc 文件中有 save=false,你可能需要使用它。

¥--save or -S will tell npm to remove the package from your package.json, npm-shrinkwrap.json, and package-lock.json files. This is the default, but you may need to use this if you have for instance save=false in your .npmrc file.

确认本地包卸载

¥Confirming local package uninstallation

要确认 npm uninstall 正常工作,请检查 node_modules 目录是否不再包含已卸载包的目录。

¥To confirm that npm uninstall worked correctly, check that the node_modules directory no longer contains a directory for the uninstalled package(s).

  • Unix 系统(如 OSX):ls node_modules

    ¥Unix system (such as OSX): ls node_modules

  • Windows 系统:dir node_modules

    ¥Windows systems: dir node_modules

卸载全局包

¥Uninstalling global packages

要卸载无范围的全局包,请在命令行上使用带有 -g 标志的 uninstall 命令。如果包是范围的,则包括范围。

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

无范围的包

¥Unscoped package

npm uninstall -g <package_name>

范围包

¥Scoped package

npm uninstall -g <@scope/package_name>

示例

¥Example

例如,要卸载名为 jshint 的包,请运行:

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

npm uninstall -g jshint

资源

¥Resources

卸载本地包

¥Uninstalling local packages

卸载全局包

¥Uninstalling global packages

npm 中文网 - 粤ICP备13048890号