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

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

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


当前回答

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

(我更倾向于在使用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.

其他回答

你可以使用另一个npm包来实现这个目的。 通过将其安装到本地文件夹using

NPM I rm-node-modules- recurur

如果你愿意,你也可以用-g开关全局安装它。

如果安装在本地,可以从当前目录node_modules.bin\ using调用二进制文件

 .\node_modules\.bin\rmnodes "<top level directory within quotes>"

如果您选择全局安装,只需使用

rmnodes "<top level directory within quotes>"

就是这样。这个包最终将轻松地递归地从所有子目录中删除node_modules(在我的例子中大约有60多个文件夹)。参考所附快照。 使用rm-node-modules-recur

只需使用powershell..

运行powershell和cd到父文件夹,然后:

rm [yourfolder]

如:

rm node_modules

在Windows上

执行以下命令删除node_modules及其子目录下的文件,并删除其中的文件夹:

DEL /F/S/Q node_modules > NUL 2>&1  &  RMDIR /S/Q node_modules > NUL 2>&1

我使用Winrar简单地做到了这一点,这可能看起来是一个奇怪的解决方案,但工作得非常好。

右键单击node_modules文件夹 选择Add to archive…菜单上的。 打开Winrar对话框 只要检查归档后删除文件的选项 完成后不要忘记删除node_modules.rar。

(更新) 这也适用于7Zip


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