How to Delete node_modules - Deep Nested Folder in Windows

前端 未结 30 921
逝去的感伤
逝去的感伤 2020-12-02 03:25

Upon trying to remove the node_modules directory created by npm install:

The source file name(s) are larger than is su

相关标签:
30条回答
  • 2020-12-02 04:07

    On Windows my go to solution is using the rmdir command:

    rd /S .\node_modules\

    If it fails the first time -- try one more time. Also check if you have running scripts currently using the modules (npm run serve or similar).

    0 讨论(0)
  • 2020-12-02 04:07

    I needed to clean up an entire Projects directory for backup purposes, so I installed rimraf and ran this at the root dir (inside a git bash prompt):

    find . -name "node_modules" -type d -prune -exec rimraf '{}' +
    

    Very effective, truly recursive (avoids children node_modules) and fast on windows (thanks to rimraf).

    Sources:

    1. https://rtmccormick.com/2018/01/10/clear-node-modules-folders-recursively-mac-linux/
    2. The accepted answer in this question that suggests rimraf but lacks in the recursive aspect
    0 讨论(0)
  • 2020-12-02 04:07

    The PowerShell way:

    PS > rm -r -force node_modules
    
    # The same, but without using aliases
    PS > Remove-Item -Recurse -Force node_modules
    

    And if you want to delete every node_modules in sub directories:

    Note Potentially dangerous as it deletes recursively, be sure of what you're doing here

    PS > dir -Path . -Filter node_modules -recurse | foreach {echo $_.fullname; rm -r -Force $_.fullname}
    
    0 讨论(0)
  • 2020-12-02 04:08

    Please save yourself the need to read most of these answers and just use npx rather than trying to install rimraf globally. You can run a single command and always have the most recent version with none of the issues seen here.

    npx rimraf ./**/node_modules
    
    0 讨论(0)
  • 2020-12-02 04:08

    simple just run for windows I haven't tested it for other operating systems

    rm -r node_modules
    

    in fact, you can delete any folder with this.

    like rm -r AnyFolderWhichIsNotDeletableFromShiftDeleteOrDelete.

    just open the gitbash move to root of the folder and run this command

    Hope this will help.

    Thanks, Ajay Kotnala

    0 讨论(0)
  • 2020-12-02 04:09

    Okay so my problem was that i had .bin folder inside node_modules and i wasn't able to delete that, I tried all the above solutions for the same but nothing worked.

    Error which was repeating was "u do not have permission to delete the folder or its been used by some other program".

    Solution that i found "I had Antivirus installed on my pc ,which was unknowingly using the files from node_modules folder".

    I uninstalled the antivirus or u can change permission setting from antivirus setting option (depends on which antivirus u have).Now i am able to delete node_modules folder.

    0 讨论(0)
提交回复
热议问题