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

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

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


当前回答

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

其他回答

删除深网文件夹,如Windows中的node_modules

选项1 使用rimraf NPM包删除 打开命令提示符并将目录更改为所在的文件夹 存在Node_modules文件夹。 运行 rimraf node_modules 缺少rimraf错误,然后安装 NPM安装rimraf 安装完成后,运行 rimraf node_modules 选项2: Detele没有安装任何东西 在任意驱动器中创建名为test的文件夹 robocopy /MIR c:\test D:\UserData\FolderToDelete > NUL 删除文件夹test和FolderToDelete,因为它们都是空的

为什么这在windows中是一个问题?

其中一个深度嵌套的文件夹结构是node_modules, Windows无法删除该文件夹,因为它的名称太长。要解决这个问题,简单的解决方案,安装一个节点模块RimRaf

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

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

来源:

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

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

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

这太简单了。

只需删除node_modules中的所有文件夹,然后删除实际的node_module文件夹。

这对我有用。最好的运气……