windows 删除 node_modules 文件夹

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29915328/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 19:02:36  来源:igfitidea点击:

removing node_modules folder

windowsnpmdirectoryyeoman

提问by deostroll

The problem:

问题:

I've created a yeoman project by mistake on my windows box. Via explorer when I try to delete it I get an error saying that the path is too long.

我错误地在我的 Windows 盒子上创建了一个自耕农项目。通过资源管理器尝试删除它时,我收到一条错误消息,指出路径太长。

Source too long error

来源过长错误

Several Solutions:

几种解决方案:

But is there a script based solution?

但是有基于脚本的解决方案吗?

采纳答案by deostroll

You can write powershell to this effect relying on npm

您可以根据 npm

PS C:\code\yeoman-foo> ls node_modules | foreach {
>> echo $("Deleting module..." + $_.Name)
>> & npm rm $_.Name
>> }
>>

After the above command completes you can remove the folder by the traditional ways...

上述命令完成后,您可以通过传统方式删除文件夹...

Go to the parent folder containing the project folder, select it, and SHIFT+ DEL

转到包含项目文件夹的父文件夹,选择它,然后SHIFT+DEL

回答by Mac

You could use rimraf:

你可以使用rimraf

npm install -g rimraf
rimraf C:\code\yeoman-foo

回答by What Would Be Cool

You should be able to use the force switch. This script recursively removes any node_modules folder using PowerShell 3.

您应该可以使用强制开关。此脚本使用 PowerShell 3 递归删除任何 node_modules 文件夹。

:> ls node_modules -Recurse -Directory | foreach { rm $_ -Recurse -Force }

回答by j_quelly

  1. npm install -g remove-node-modules
  2. cd to root and remove-node-modules
  3. or remove-node-modules path/to/folder
  1. npm install -g remove-node-modules
  2. cd 到 root 和 remove-node-modules
  3. 或者 remove-node-modules path/to/folder

Source:

来源:

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

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

回答by Arno van Oordt

Easiest way I found so far (no installing or separate programs required) is to just run these commands in the root of your project (next to the node_modules folder):

到目前为止我发现的最简单的方法(不需要安装或单独的程序)是在项目的根目录(在 node_modules 文件夹旁边)运行这些命令:

mkdir temp_dir
robocopy temp_dir node_modules /s /mir
rmdir temp_dir
rmdir node_modules

For convinience you can also put this code in a .bat file and place it in the project root and run it whenever you want to remove the entire node_modules map

为方便起见,您还可以将此代码放在 .bat 文件中并将其放在项目根目录中,并在您想要删除整个 node_modules 映射时运行它

回答by Stuart Hallows

Try this rmdir node_modules /s /q

尝试这个 rmdir node_modules /s /q