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


当前回答

只需切换到您的%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) ?

其他回答

简单地使用下面的MAC,

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

只需切换到您的%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) ?

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

下面是我尝试的一个更优雅的解决方案,我让npm为我做所有的工作。

# On Linux Mint 19.1 Cinnamon
# First navigate to where your global packages are installed.

$ npm root # returns /where/your/node_modules/folder/is
$ cd /where/your/node_modules/folder/is # i.e for me it was cd /home/user/.npm-packages/lib/node_modules

然后,如果你进行npm卸载或npm删除,这些模块将被视为正常的项目依赖项。它甚至生成一个包锁。Json文件,当它完成:

$ npm remove <package-name> # you may need sudo if it was installed using sudo  

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

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