在尝试删除npm install创建的node_modules目录时:

源文件名大于该文件支持的文件名 系统。尝试移动到路径名称较短的位置,或者尝试 在尝试此操作之前,将名称重命名为较短的名称

我也尝试了shift + delete,仍然有同样的问题。


当前回答

什么都试过了,但都没用。以上所有方法都不起作用。最后,我能够通过VSCode删除。

用VSCode打开你的根文件夹。 选择“node_modules”文件夹并删除。 利润。(删除需要几毫秒。)

其他回答

PowerShell方式:

PS > rm -r -force node_modules

# The same, but without using aliases
PS > Remove-Item -Recurse -Force node_modules

如果你想删除子目录中的所有node_modules:

注意递归删除的潜在危险,请确保您在这里所做的事情

PS > dir -Path . -Filter node_modules -recurse | foreach {echo $_.fullname; rm -r -Force $_.fullname}

您可以使用Git Bash删除文件夹:

例子: c: \ \用户olefrank \ \ mynodeproject项目

Rm -rf /c/users/olefrank/projects/mynodeproject

我还没有在其他操作系统上测试过

rm -r node_modules

事实上,你可以用它删除任何文件夹。

比如rm -r anyfolderwherhisnotdeletablefromshiftdeleteordelete。

只需打开github移动到文件夹的根目录并运行此命令

希望这能有所帮助。

谢谢, Ajay Kotnala

从这篇MSDN文章来看,看起来你现在可以绕过Windows 10 v1607中的MAX_PATH限制(又名“周年更新”),通过更改注册表中的值-或通过组策略

我使用的一个解决方案是:

(我更倾向于在使用CI环境时避免安装新的扩展(rimraf)。)

A) Rename packages.json to something else. B) Specially on CI - after npm install, I usually remove the file instead of renaming it, but if you need it, you don't have to do this. That's your choice. run npm init - this will create an empty packages.json file (no dependencies) run npm prune - this will match node_modules with the dependencies section of packages.json - which is now empty as the result of step #2. If you have chosen #1.A. step, delete the newly created packages.json, and rename original packages.json back to its original name.