如何卸载 package.json (NPM) 中列出的所有依赖项? [英] How do you uninstall all dependencies listed in package.json (NPM)?
问题描述
如果我在我的应用程序根目录中定义了 package.json 文件并运行 npm install -g
它将安装 package.json 中定义的所有依赖项,全局.
If I have a package.json file defined in my application root and run npm install -g
it will install all the dependencies defined in package.json, globablly.
然而,这似乎不能反过来.
However, this doesn't seem to work in reverse.
如果我在我的应用程序根目录中执行 npm uninstall -g
它会抛出一个错误,期望我向它传递一个包名.
If I do npm uninstall -g
in my application root it throws an error, expceting me to pass it a package name.
这不应该也卸载我安装的相同软件包吗?
Shouldn't this also uninstall the same packages I installed?
我做错了吗?
推荐答案
如果使用 Bash,只需切换到包含 package.json 文件的文件夹并运行以下命令:
If using Bash, just switch into the folder that has your package.json file and run the following:
for package in `ls node_modules`; do npm uninstall $package; done;
对于全局安装的包,切换到 %appdata%/npm
文件夹(如果在 Windows 上)并运行相同的命令.
In the case of globally-installed packages, switch into your %appdata%/npm
folder (if on Windows) and run the same command.
此命令与 npm 3.3.6(节点 5.0)中断.我现在正在使用以下 Bash 命令,该命令已映射到我的 .bashrc 文件中的 npm_uninstall_all:
npm uninstall `ls -1 node_modules | tr '/\n' ' '`
注意:它会从 package.json 和 package-lock.json 中删除所有依赖项列表,使 npm install
变得无用,因为没有列出要安装的依赖项.
Note: It would remove all dependencies list from package.json and package-lock.json rendering npm install
useless as there would be no dependencies listed to be installed.
增加了奖金?速度更快!
Added bonus? it's way faster!
https://github.com/npm/npm/issues/10187
这篇关于如何卸载 package.json (NPM) 中列出的所有依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!