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


当前回答

简单地使用下面的MAC,

Sudo rm -rf /usr/local/ {bin /{节点,npm}, lib / node_modules / npm、lib /节点,共享/男人/ /节点。}

其他回答

Windows:

rmdir /s /q "%appdata%/npm"

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

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

对于使用Powershell的用户:

npm -gp ls --depth=0 | ForEach-Object { Get-Item $_ } | Where { $_.Name -ne 'npm' } | ForEach-Object { npm rm -g $_.Name }

清除缓存。

npm cache clear

在Windows系统中,转到 “C:\Users{username}\AppData\Roaming”目录并手动删除npm文件夹

npm ls -gp | awk -F/ '/node_modules/&&!/node_modules.*node_modules/&&!/npm/{print $NF}' | xargs npm rm -g