选择命令行版本:
🌐 Synopsis
npm uninstall [<@scope>/]<pkg>...aliases: unlink, remove, rm, r, un
🌐 Description
这将卸载一个包,完全删除代表它安装的所有 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.
--no-save 会告诉 npm 不要从你的 package.json、npm-shrinkwrap.json 或 package-lock.json 文件中移除该包。
--save 或 -S 会告诉 npm 从你的 package.json、npm-shrinkwrap.json 和 package-lock.json 文件中移除该包。这是默认行为,但如果你的 npmrc 文件中例如有 save=false,你可能需要使用这个命令
在全局模式下(即在命令后附加 -g 或 --global 时),它会将当前的包上下文作为全局包卸载。在这种情况下,--no-save 会被忽略。
🌐 In global mode (ie, with -g or --global appended to the command), it uninstalls the current package context as a global package. --no-save is ignored in this case.
作用域是可选的,并遵循 scope 的常规规则。
🌐 Scope is optional and follows the usual rules for scope.
🌐 Examples
npm uninstall sax
sax 将不再出现在你的 package.json、npm-shrinkwrap.json 或 package-lock.json 文件中。
npm uninstall lodash --no-save
lodash 不会从你的 package.json、npm-shrinkwrap.json 或 package-lock.json 文件中删除。
🌐 Configuration
savetrue,除非使用 npm update 时,默认值为 false将已安装的软件包保存到 package.json 文件中作为依赖。
🌐 Save installed packages to a package.json file as dependencies.
与 npm rm 命令一起使用时,会移除对 package.json 的依赖。
🌐 When used with the npm rm command, removes the dependency from package.json.
如果设置为 false,也将阻止向 package-lock.json 写入。
🌐 Will also prevent writing to package-lock.json if set to false.
global以“全局”模式运行,因此软件包会安装到 prefix 文件夹中,而不是当前工作目录。有关行为差异的更多信息,请参见 folders。
🌐 Operates in "global" mode, so that packages are installed into the prefix folder instead of the current working directory. See folders for more on the differences in behavior.
{prefix}/lib/node_modules 文件夹中,而不是当前工作目录。{prefix}/bin 关联{prefix}/share/manworkspace启用在当前项目的已配置工作区的上下文中运行命令,同时通过仅运行此配置选项定义的工作区进行过滤。
🌐 Enable running a command in the context of the configured workspaces of the current project while filtering by running only the workspaces defined by this configuration option.
workspace 配置的有效值为以下之一:
🌐 Valid values for the workspace config are either:
对于 npm init 命令设置时,可以将其设置为一个尚不存在的工作区文件夹,以创建该文件夹并将其作为项目内全新的工作区进行设置。
🌐 When set for the npm init command, this may be set to the folder of a workspace which does not yet exist, to create the folder and set it up as a brand new workspace within the project.
此值不会导出到子进程的环境中。
🌐 This value is not exported to the environment for child processes.
workspaces设置为 true 以在 所有 配置的工作区上下文中运行命令。
🌐 Set to true to run the command in the context of all configured workspaces.
将此显式设置为 false 会导致像 install 这样的命令完全忽略工作区。如果不显式设置:
🌐 Explicitly setting this to false will cause commands like install to ignore workspaces altogether. When not set explicitly:
node_modules 树操作的命令(安装、更新等)会将工作区链接到 node_modules 文件夹。- 执行其他操作的命令(测试、执行、发布等)会在根项目上运行,除非 在 workspace 配置中指定了一个或多个工作区。此值不会导出到子进程的环境中。
🌐 This value is not exported to the environment for child processes.
include-workspace-root为命令启用工作区时包括工作区根。
🌐 Include the workspace root when workspaces are enabled for a command.
当为 false 时,通过 workspace 配置指定单个工作区,或通过 workspaces 标志指定所有工作区,将导致 npm 仅在指定的工作区上操作,而不会在根项目上操作。
🌐 When false, specifying individual workspaces via the workspace config, or all workspaces via the workspaces flag, will cause npm to operate only on the specified workspaces, and not on the root project.
此值不会导出到子进程的环境中。
🌐 This value is not exported to the environment for child processes.
install-links当设置文件时:协议依赖将作为常规依赖被打包和安装,而不会创建符号链接。此选项对工作区没有影响。
🌐 When set file: protocol dependencies will be packed and installed as regular dependencies instead of creating a symlink. This option has no effect on workspaces.
🌐 See Also