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

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

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


当前回答

NPM install -g remove-node-modules CD到根目录并删除节点模块 或删除节点模块路径/到/文件夹

来源:

https://github.com/j-quelly/node-cleanup

其他回答

仅使用DOS命令DELETE,无需任何安装:

在C或D盘上创建一个空文件夹test,并使用以下DOS命令

robocopy /MIR c:\test D:\UserData\FolderToDelete > NUL

完成上述命令后,您的文件夹将为空,现在您可以删除文件夹。

不用担心,您的测试文件夹将始终为空,因此您可以随时删除它。

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

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

在Windows上

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

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

在Windows上,使用Total Commander,你所要做的就是选择文件夹,点击shift + delete。别忘了shift键。

我只是在PowerShell的项目文件夹中执行del node_modules,它会问你是否想删除它和它的子文件夹,只需点击'Y',就是这样