如果你不再需要在代码中使用包,我们建议将其卸载并将其从项目的依赖中删除。
🌐 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
要从你的 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
🌐 Removing a local package without removing it from package.json
使用 --no-save 将告诉 npm 不要从你的 package.json、npm-shrinkwrap.json 或 package-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.json、npm-shrinkwrap.json 和 package-lock.json 文件中移除该包。这是默认行为,但如果你的 .npmrc 文件中有例如 save=false,你可能需要使用它。
🌐 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).
ls node_modulesdir 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