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


当前回答

只要把你的控制台:

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

这是我的工作……

其他回答

如果你有Intellij Webstorm,你可以使用它内置的图形包管理器。

以root用户打开并创建一个空项目。去

>文件设置>语言和框架> Node.js和NPM

在那里您将看到所有已安装的包。卸载很容易,你可以选择和取消选择任何包,你想卸载,Ctrl+一个工作以及。

对于一种更手动的方法,它不涉及文件浏览器,不关心安装在哪里,以后不太可能崩溃,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次,这就容易多了。

sed的解决方案

npm -gp ls | sed -r '/npm$|(node_modules.*){2,}/d; s:.*/([^/]+)$:\1:g' | xargs npm rm -g

你可以在以下位置找到你所有安装的npm包:

C:\Users\username\AppData\Roaming\npm

并删除你想删除的NPM内容。

如果AppData没有显示,这意味着它被隐藏了,你可以在文件资源管理器中查看并选中隐藏项,然后你可以看到所有隐藏的文件夹。

只要把你的控制台:

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

这是我的工作……