Programming

node_modules를 삭제하는 방법-Windows에서 깊은 중첩 폴더

procodes 2020. 5. 7. 20:18
반응형

node_modules를 삭제하는 방법-Windows에서 깊은 중첩 폴더


다음에 의해 작성된 node_modules 디렉토리 를 제거하려고 할 때 npm install:

소스 파일 이름이 파일 시스템이 지원하는 것보다 큽니다. 경로 이름이 더 짧은 위치로 이동하거나이 작업을 시도하기 전에 더 짧은 이름으로 이름을 바꾸십시오.

나는 또한 shift+ 를 시도했지만 delete여전히 같은 문제가 있습니다.


이것이 최고의 Google 결과이기 때문에 이것이 나를 위해 일한 것입니다.

RimRaf 설치 :

npm install rimraf -g

그리고 프로젝트 폴더에서 다음을 사용하여 node_modules 폴더를 삭제하십시오.

rimraf node_modules

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


Winrar를 사용하여 간단하게 수행했지만 이상한 해결책처럼 보이지만 잘 작동합니다.

  • node_modules폴더를 마우스 오른쪽 버튼으로 클릭하십시오
  • 메뉴 Add to archive ...에서 선택하십시오 .
  • Winrar 대화 상자가 열립니다
  • 옵션을 확인하십시오. delete files after archiving
  • 완료 후 node_modules.rar를 삭제하는 것을 잊지 마십시오.


[업데이트] 7Zip에서도 작동합니다



C 또는 D 드라이브에 빈 폴더 "test"를 작성하고 다음 DOS 명령을 사용하십시오.

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

위의 명령을 완료하면 폴더가 비어 있으므로 폴더를 삭제할 수 있습니다.

테스트 폴더가 항상 비어 있다는 것을 걱정하지 마십시오. 언제든지 삭제할 수 있습니다.


Git Bash를 사용하여 폴더를 제거 할 수 있습니다.

예 : c : \ users \ olefrank \ projects \ mynodeproject

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


Windows에서 node_modules와 같은 Deep Netsted Folder 삭제

  1. 옵션 1

    rimrafNPM 패키지를 사용하여 삭제

    • 명령 프롬프트를 열고 디렉토리가 폴더가있는 node_modules폴더 로 변경하십시오 .

    • 운영

      rimraf node_modules

    • rimraf ERROR 누락 후 설치

      npm install rimraf -g

    • 설치가 완료되면 다음을 실행하십시오.

      rimraf node_modules

  2. 옵션 2 :

    아무것도 설치하지 않고 Detele

    • test모든 드라이브에 이름 가진 폴더 만들기

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

    • 폴더를 삭제 test하고 FolderToDelete모두 비어 있습니다

왜 이것이 Windows에서 문제입니까?

깊은 중첩 폴더 구조 중 하나는 node_modules이며, 이름이 너무 길어서 Windows에서 폴더를 삭제할 수 없습니다 . 이 쉬운 솔루션을 해결하려면 노드 모듈 RimRaf를 설치하십시오.


폴더를 제거하기 위해 GitBash를 사용했습니다!

rm -r node_modules

모든 것을 삭제하는 데 시간이 걸렸지 만 나를 위해 일했습니다!


Git Bash를 사용하여 폴더를 제거 할 수 있습니다.

예 : c : \ users \ stu \ projects \ mynodeproject

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


Visual Studio 코드 사용해보기

많은 솔루션을 시도한 후에 이것은 매우 간단하다는 것을 알았습니다. Visual 코드로 프로젝트를 열고 삭제하십시오. UI가 몇 초 동안 정지 될 수 있지만 확실히 작동합니다. 많은 큰 크기의 node_modules 폴더를 사용하여 테스트

여기에 이미지 설명을 입력하십시오

감사


비슷한 문제가 있었고 알 수없는 이유로 RD가 작동하지 않았습니다.

NPM은 자체 엉망을 제거 할 수 있으므로 npm uninstall [module-name]node_modules의 각 디렉토리에 대해 제거하면 제거 할 수 있습니다.

(종속성이 많은 사람들을 위해 나중에 이것을 일괄 루프하는 방법을 찾을 것입니다.)


  1. npm install -g remove-node-modules
  2. 루트로 cd 및 remove-node-modules
  3. 또는 remove-node-modules path/to/folder

출처:

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


Windows에서 Total Commander를 사용 하면 shift+를 클릭하여 폴더를 선택하기 만하면 delete됩니다. shift열쇠를 잊지 마십시오 .


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


I just do del node_modules inside my project folder on PowerShell, it will ask you if you want to remove it and its children folder, just hit 'Y' and that's it


Any file manager allow to avoid such issues, e.g Far Manager

여기에 이미지 설명을 입력하십시오


One solution that I use:

(I would prefer to avoid installing a new extension (rimraf) when working with CI environments.)

  1. 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.
  2. run npm init - this will create an empty packages.json file (no dependencies)
  3. 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.
  4. If you have chosen #1.A. step, delete the newly created packages.json, and rename original packages.json back to its original name.

Its too easy.

Just delete all folders inside node_modules and then delete actual node_module folder.

This Works for me. Best luck....


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).


From this looks of this MSDN article, it looks like you can now bypass the MAX_PATH restriction in Windows 10 v1607 (AKA 'anniversary update') by changing a value in the registry - or via Group Policy


Just use powershell..

Run powershell and cd to the parent folder and then:

rm [yourfolder]

as in:

rm node_modules

I'm on windows 10 and I could'nt delete folders with message "directory not emtpy". Neither rimraf nor rm -rf worked.

Copying an empty text file to every single folder did the trick - I was able to delete the complete node_modules folder.


Sometimes, even if you install rimraf globally you can have a local rimraf dependency (SASS usually have it). In this case I would run following commands:

Follow first 2 steps as usagidon recommended, if you have issues or errors try

npm uninstall rimraf & rimraf node_modules

this will delete local rimraf and use the global one


Not exactly related, but as this is the first post I found in my search for a similar solution I think it's worth posting here.

I was running into permission issues on Windows 10 trying to delete my node_modules folder after a failed attempt at installing electron-redux. It seems electron-redux added @types to my node_modules, which had incorrect permissions set up.

rimraf did not work as it still ran into permission issues.

I ended up renaming node_modules then a simple delete worked.


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.


What worked for me was:

  1. closed the node manager console
  2. closed the Atom (visual studio code ) dev environment you are in.
  3. then delete the node_modules

    npm install rimraf -g 
    rimraf node_modules
    

Many build runners come with a clean task. This task usually just removes a bunch of files so you can start with a fresh working copy to start building into. Well, turns out that Bash has a pretty good clean command all by itself: rm. Passing the -r (recursive) flag lets rm remove directories too! It couldn’t be simpler:

Install globally rimraf:

npm install rimraf -g

Add cleaning task like below:

"devDependencies": {
  "rimraf": "latest"
},
"scripts": {
  "clean": "rimraf node_modules"
}

For more details, there is a section about cleaning task using rimraf here


Tried everything but didn't work. All the above methods did nothing. At last I was able to delete via VSCode.

  1. Just Open your root folder with VSCode.
  2. Select node_modules folder and delete.
  3. Profit. (It will take few milliseconds to delete.)

VSCode-delete.png


Advance a little beat for multiple folders...

'node_module'을 포함하는 'build'가 여러 개인 프로젝트 폴더가있는 경우 처럼:

C:/Project/build-1/node_modules
C:/Project/build-2/node_modules
C:/Project/build-3/node_modules
C:/Project/build-4/node_modules

"빌드"로 시작하는 모든 폴더를 삭제하려고합니다.

! 위에서 제안한대로 nodejsrimraf먼저 설치 하십시오 !

그런 다음 프로젝트 경로로 이동하여 PowerShell 명령을 실행하십시오.

cd  C:/Project/
Get-ChildItem build* | foreach {rimraf -Path $_.FullName}

와일이 필요해


node_modules 폴더에서 cmd를 사용하여 경로로 이동하고 아래 명령을 적용하십시오.

npm install rimraf -g 
rimraf node_modules

참고 URL : https://stackoverflow.com/questions/28175200/how-to-delete-node-modules-deep-nested-folder-in-windows

반응형