是否有删除所有全局npm模块的命令?如果没有,你有什么建议?


当前回答

sudo npm list -g --depth=0. | awk -F ' ' '{print $2}' | awk -F '@' '{print $1}'  | sudo xargs npm remove -g

为我工作

Sudo NPM list -g——depth=0。列出所有已安装的顶级 awk -F ' ' '{print $2}'摆脱├── awk -F '@' '{print $1}'获取'@'之前的部分 Sudo xargs NPM remove -g全局删除包

其他回答

使用此代码卸载任何包:

npm rm -g <package_name>

环球纱线

nano ~/.config/yarn/global/package.json
<Manually remove all packages from package.json>
yarn global add

或者,如果你不关心package.json中的实际内容

echo {} >  ~/.config/yarn/global/package.json && yarn global add

这应该也适用于NPM,但我不确定NPM全局存储在哪里。

对于一种更手动的方法,它不涉及文件浏览器,不关心安装在哪里,以后不太可能崩溃,100%跨平台兼容,并且由于额外的步骤而感觉更安全,请使用这种方法。

npm ls -g --depth=0 Copy output Paste into favorite code editor (I use vsCode. Great multi-cursor editing) Check for any packages you'd like to keep (nodemon, yarn, to name a few) Remove those lines Remove every instance of +-- or other line decorators Remove all the version information (eg '@2.11.4') Put all items on same line, space separated Add npm uninstall -g to beginning of that one line. Mine looks like npm uninstall -g @angular/cli @vue/cli express-generator jest mocha typescript bindings nan nodemon yarn, but I didn't install many packages globally on this machine. Copy line Paste in terminal, hit enter if not already added from the copy/paste Look for any errors in the terminal. Check npm ls -g to make sure it's complete. If something got reinstalled, rinse and repeat

其他仅使用cli的方法非常适合计算机管理员从相同的ssh或Puppet同时为100台几乎相同的计算机做一些事情。但如果你只做一次,甚至一年5次,这就容易多了。

因为这是搜索中最热门的答案,所以我把它贴在这里,因为这是我过去用来清洁电脑切换笔记本电脑的解决方案。

cd ~/Documents # or where you keep your projects
find . -name "node_modules" -exec rm -rf '{}' +

来源:https://winsmarts.com/delete-all-node-modules-folders-recursively-on-windows-edcc9a9c079e

只需切换到您的%appdata%/npm目录并运行以下…

for package in `ls node_modules`; do npm uninstall $package; done;

EDIT:这个命令在npm 3.3.6 (Node 5.0)中中断。我现在使用以下Bash命令,我已经映射到我的.bashrc文件中的npm_uninstall_all:

npm uninstall `ls -1 node_modules | tr '/\n' ' '`

额外的好处?这要快得多!

https://github.com/npm/npm/issues/10187

如何卸载包中列出的所有依赖项。json (NPM) ?