在尝试删除npm install创建的node_modules目录时:
源文件名大于该文件支持的文件名 系统。尝试移动到路径名称较短的位置,或者尝试 在尝试此操作之前,将名称重命名为较短的名称
我也尝试了shift + delete,仍然有同样的问题。
在尝试删除npm install创建的node_modules目录时:
源文件名大于该文件支持的文件名 系统。尝试移动到路径名称较短的位置,或者尝试 在尝试此操作之前,将名称重命名为较短的名称
我也尝试了shift + delete,仍然有同样的问题。
当前回答
我也遇到过类似的问题,由于一些未知的原因,RD没有工作。
NPM可以摆脱它自己的混乱,所以如果你为node_modules中的每个目录执行NPM uninstall [module-name],你就可以摆脱它们了。
(对于那些有很多依赖关系的人,我将在后面查找如何批量循环。)
其他回答
我使用的一个解决方案是:
(我更倾向于在使用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.
为了备份,我需要清理整个Projects目录,所以我安装了rimraf并在根目录下运行(在git bash提示符中):
find . -name "node_modules" -type d -prune -exec rimraf '{}' +
非常有效,真正的递归(避免子node_modules),在windows上快速(感谢rimraf)。
来源:
https://rtmccormick.com/2018/01/10/clear-node-modules-folders-recursively-mac-linux/ 这个问题的公认答案暗示了rimraf,但在递归方面缺乏
你可以使用另一个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
你可以根据@mike-caron的答案进行简单的批处理,这样你就不需要每次都输入整个robocopy命令,而只是输入所选文件夹的路径:
@echo off
ECHO What Directory would you like to empty?
ECHO Current path: %cd%
SET /p UserInputPath=Input relative path to directory:
ROBOCOPY /MIR empty_dir %cd%\%UserInputPath% > NUL
PAUSE
这里你在robocopy命令中使用名为empty_dir的空目录,需要与批处理文件在同一目录下才能工作。批处理文件完成其任务后,选定目录和empty_dir目录都将为空,以便您可以删除它们。
我做了一个简单的批处理文件,创建空文件夹,robocopy命令执行后,删除空文件夹和所选文件夹,这样你唯一需要做的就是输入你想删除的所选文件夹的路径。 如果你不想安装像rimraf这样的东西,它是快速和实用的。 你可以在这里下载https://github.com/5imun/WinCleaner
在Windows上
执行以下命令删除node_modules及其子目录下的文件,并删除其中的文件夹:
DEL /F/S/Q node_modules > NUL 2>&1 & RMDIR /S/Q node_modules > NUL 2>&1