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

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

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


当前回答

对我有用的是:

关闭节点管理器控制台 关闭您所在的Atom (visual studio代码)开发环境。 然后删除node_modules NPM安装rimraf rimraf node_modules

其他回答

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

来源:

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

您可以使用Git Bash删除文件夹:

例子: c: \ \用户olefrank \ \ mynodeproject项目

Rm -rf /c/users/olefrank/projects/mynodeproject

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

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

在Windows上,我的解决方案是使用rmdir命令:

rd /S .\node_modules\

如果第一次失败了,那就再试一次。 还要检查当前是否有正在运行的脚本使用这些模块(npm run serve或类似的)。