node.js 如何删除 node_modules - Windows 中的深层嵌套文件夹

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28175200/
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-02 18:21:03  来源:igfitidea点击:

How to Delete node_modules - Deep Nested Folder in Windows

node.jswindows-7npm

提问by leoh

Upon trying to remove the node_modulesdirectory created by npm install:

在尝试删除由以下创建的node_modules目录时npm install

The source file name(s) are larger than is supported by the file system. Try moving to a location which has a shorter path name, or try renaming to shorter name(s) before attempting this operation

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

I also tried shift+ deleteand still having the same issue.

我也试过shift+delete仍然有同样的问题。

回答by blub

Since this the top google result, this is what worked for me:

由于这是谷歌的顶级结果,这对我有用:

Install RimRaf:

安装 RimRaf:

npm install rimraf -g

npm install rimraf -g

And in the project folder delete the node_modules folder with:

并在项目文件夹中删除 node_modules 文件夹:

rimraf node_modules

rimraf node_modules

If you want to recursively delete:

如果要递归删除:

rimraf .\**\node_modules

rimraf .\**\node_modules

[ http://www.nikola-breznjak.com/blog/nodejs/how-to-delete-node_modules-folder-on-windows-machine/]

[ http://www.nikola-breznjak.com/blog/nodejs/how-to-delete-node_modules-folder-on-windows-machine/]

回答by Eymen Elkum

I've simply done that by using Winrar, this may seem a strange solution but working very well.

我只是通过使用 Winrar 做到了这一点,这似乎是一个奇怪的解决方案,但效果很好。

  • right click on node_modulesfolder
  • select Add to archive ...from the menu.
  • Winrar dialog opens
  • just check the option delete files after archiving
  • Don't forget to delete the node_modules.rar after finished.
  • 右键单击node_modules文件夹
  • 选择Add to archive ...从菜单。
  • Winrar 对话框打开
  • 只需检查选项 delete files after archiving
  • 完成后不要忘记删除node_modules.rar。



[更新] 这也适用于 7Zip



回答by Ali Adravi

DELETE only by using DOS command without any installation:

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

Create an empty folder "test" on C or D drive and use following DOS command

在 C 或 D 驱动器上创建一个空文件夹“test”并使用以下 DOS 命令

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

After completing above command, your folder will be empty, now you can delete the folder.

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

Don't worry your test folder will always be empty, so you can delete it at any time.

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

回答by olefrank

You can use Git Bash to remove the folder:

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

example: c:\users\olefrank\projects\mynodeproject

例如: c:\users\olefrank\projects\mynodeproject

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

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

回答by Bruno DM

I used GitBash to remove de folder!

我用 GitBash 删除了 de 文件夹!

rm -r node_modules

It took a while to delete everything, but worked for me!

删除所有内容花了一段时间,但对我有用!

回答by Jinna Balu

Delete Deep Netsted Folder like node_modules in Windows

在 Windows 中删除像 node_modules 这样的 Deep Netsted 文件夹

  1. Option 1

    Delete using rimrafNPM package

    • Open command prompt and change your directory to the folder where node_modulesfolder exists.

    • Run

      rimraf node_modules

    • Missing rimraf ERROR then Install

      npm install rimraf -g

    • When the installation completes, run

      rimraf node_modules

  2. Option 2:

    Detele without installing anything

    • Create a folder with name testin any Drive

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

    • delete the folder testand FolderToDeleteas both are empty

  1. 选项1

    使用rimrafNPM 包删除

    • 打开命令提示符并将目录更改为文件夹所在的 node_modules文件夹。

    • rimraf node_modules

    • 缺少 rimraf 错误然后安装

      npm install rimraf -g

    • 安装完成后,运行

      rimraf node_modules

  2. 选项2

    删除不安装任何东西

    • test在任何云端硬盘中创建一个具有名称的文件夹

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

    • 删除文件夹testFolderToDelete因为两者都是空的

Why this is an issue in windows?

为什么这是 Windows 中的问题?

One of the deep nested folder structure is node_modules, Windows can't delete the folder as its name is too long. To solve this, Easy solution, install a node module RimRaf

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

回答by Umar Abbas

Try Visual Studio Code

尝试 Visual Studio 代码

After trying many solution i find this one is pretty simple. just open the project in Visual code and delete it. the UI may freeze for some seconds but it will definitely works.I test using many large size node_modules folder with it

在尝试了许多解决方案后,我发现这个非常简单。只需在可视化代码中打开项目并删除它。UI 可能会冻结几秒钟,但它肯定会起作用。我使用许多大型 node_modules 文件夹进行测试

enter image description here

在此处输入图片说明

Thanks

谢谢

回答by Stuart.Sklinar

You can use Git Bash to remove the folder:

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

example: c:\users\stu\projects\mynodeproject

示例: c:\users\stu\projects\mynodeproject

rm /c/users/stu/projects/mynodeproject -rfd

rm /c/users/stu/projects/mynodeproject -rfd

回答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 Chris

I had a similar problem and RD didn't work, for some unknown reason.

我遇到了类似的问题,但由于某种未知原因,RD 无法正常工作。

NPM can get rid of its own mess though, so if you do npm uninstall [module-name]for each directory in node_modules, you'll get rid of them.

NPM 可以摆脱它自己的混乱,所以如果你npm uninstall [module-name]为 node_modules 中的每个目录做,你就会摆脱它们。

(I'll look up how to batch loop this later, for those who have lots of dependencies.)

(对于那些有很多依赖项的人,我稍后会查找如何批处理循环。)