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

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

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


当前回答

我做了一个Windows上下文项来快速删除node_modules或其他文件夹。 当Windows因为目录路径中的一些无效字符而不删除文件夹时,我使用它。

如何安装?

安装rimraf => 创建一个名为delete.bat的新文件,设置如下内容并将其复制到c:\windows\system32\ delete.bat:

 @ECHO OFF
 ECHO.
 ECHO %CD% 
 ECHO.
 ECHO Are you sure to delete the folder with Rimraf?
 PAUSE
 SET FOLDER=%CD%
 CD /

 rimraf "%FOLDER%"

 rem DEL /F/Q/S "%FOLDER%" > NUL
 rem RMDIR /Q/S "%FOLDER%"

 EXIT

fast-delete运行。要导入注册表的Reg文件。 完成了!

其他回答

我用giitbash删除文件夹!

rm -r node_modules

我花了一些时间删除所有内容,但对我来说很有效!

我也遇到过类似的问题,由于一些未知的原因,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.

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}

任何文件管理器都可以避免这样的问题,例如Far manager