简体   繁体   English

删除 node_modules 文件夹

[英]removing node_modules folder

The problem:问题:

I've created a yeoman project by mistake on my windows box.我错误地在我的 Windows 盒子上创建了一个自耕农项目。 Via explorer when I try to delete it I get an error saying that the path is too long.当我尝试通过资源管理器删除它时,我收到一条错误消息,指出路径太长。

来源过长错误

Several Solutions:几种解决方案:

But is there a script based solution?但是有基于脚本的解决方案吗?

You could use rimraf :你可以使用rimraf

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

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 }

You can write powershell to this effect relying on npm你可以依靠npm编写 powershell 来达到这个效果

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

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

Source:来源:

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

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 映射时运行它

试试这个rmdir node_modules /s /q

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM