package.json (NPM)에 나열된 모든 종속성을 제거하려면 어떻게합니까?
내 응용 프로그램 루트에 package.json 파일이 정의되어 있고 실행 npm install -g
하면 package.json, globablly에 정의 된 모든 종속성이 설치됩니다.
그러나 이것은 반대로 작동하지 않는 것 같습니다.
npm uninstall -g
내 응용 프로그램 루트에서 수행 하면 오류가 발생하여 패키지 이름을 전달합니다.
내가 설치 한 동일한 패키지도 제거해야하지 않습니까?
내가 뭘 잘못하고 있니?
Bash를 사용하는 경우 package.json 파일이있는 폴더로 전환하고 다음을 실행하십시오.
for package in `ls node_modules`; do npm uninstall $package; done;
전역으로 설치된 패키지의 경우 %appdata%/npm
폴더 로 전환하고 (Windows의 경우) 동일한 명령을 실행합니다.
편집 :이 명령은 npm 3.3.6 (노드 5.0)에서 중단됩니다. 이제 .bashrc 파일에서 npm_uninstall_all에 매핑 한 다음 Bash 명령을 사용하고 있습니다.
npm uninstall `ls -1 node_modules | tr '/\n' ' '`
추가 보너스? 훨씬 빠릅니다!
https://github.com/npm/npm/issues/10187
이것은 나를 위해 일했습니다.
명령 프롬프트 또는 gitbash를 프로젝트의 node_modules 폴더에 넣고 다음을 실행하십시오.
npm uninstall *
해당 프로젝트의 모든 로컬 패키지를 제거했습니다.
Windows의 경우 node_modules dir로 이동하여 powershell에서 실행하십시오.
npm uninstall (Get-ChildItem).Name
최근에 다음과 같이 모든 개발 종속성을 제거 할 수있는 노드 명령을 찾았습니다.
npm prune --production
앞서 언급했듯이이 명령은 개발 종속성 패키지 만 제거합니다. 적어도 수동으로 할 필요가 없었습니다.
당신이에서 제거 패키지를 원한다면 사실, 그렇게 할 수있는 옵션이 없습니다 package.json
간단하게 할 npm ls
같은 디렉토리에 package.json
의존하고 사용 npm uninstall <name>
또는 npm rm <name>
제거 할 패키지.
Windows 사용자를위한 팁 : node_modules
상위 디렉토리 내에서이 PowerShell 명령을 실행하십시오 .
ls .\node_modules | % {npm uninstall $_}
// forcibly remove and reinstall all package dependencies
ren package.json package.json-bak
echo {} > package.json
npm prune
del package.json
ren package.json-bak package.json
npm i
이것은 본질적으로 가짜의 빈 package.json을 만들고 npm prune
node_modules의 모든 것을 제거하도록 호출 하고 원래 package.json을 복원하고 모든 것을 다시 설치합니다.
다른 솔루션 중 일부는 더 우아 할 수 있지만 이것이 더 빠르고 철저하다고 생각합니다. 다른 스레드에서 사람들이 node_modules 디렉토리를 삭제하는 것을 제안하는 것을 보았지만 적어도 Windows의 경우 bin 디렉토리가 누락되어 나중에 npm이 질식합니다. 아마도 Linux에서는 제대로 복원되지만 Windows는 복원되지 않습니다.
이를 위해 루프를 실행할 필요가 없습니다.
단 하나의 명령을 사용하여 모든 node_modules를 삭제할 수 있습니다.
npm uninstall `ls -1 node_modules | tr '/\n' ' '`
Powershell 사용자 : foreach($package in ls node_modules){npm uninstall $package}
감사합니다 @ JustMailer
- package.json 에서 원치 않는 종속성 제거
npm i
" npm i
"는 누락 된 deps를 설치할뿐만 아니라 package.json과 일치하도록 node_modules를 업데이트합니다.
( 모든 것을 읽을 때까지이 단계를 복제하지 마십시오 )
For me all mentioned solutions didn't work. Soo I went to /usr/lib
and run there
for package in `ls node_modules`; do sudo npm uninstall $package; done;
But it also removed the npm
package and only half of the packages (till it reached letter n).
So I tried to install node again by the node guide.
# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs
But it didn't install npm
again.
So I decided to reinstall whole node sudo apt-get remove nodejs
And again install by the guide above.
Now is NPM again working but the global modules are still there. So I checked the content of the directory /usr/lib/node_modules
and seems the only important here is npm
. So I edited the command above to uninstall everything except npm
for package in $(ls node_modules); do if [ "$package" != "npm" ]; then sudo npm uninstall $package; fi; done;
It removed all modules what were not prefixed @
. Soo I extended the loop for subdirectories.
for package in $(ls node_modules); do if [ ${package:0:1} = \@ ]; then
for innerPackage in $(ls node_modules/${package}); do
sudo npm uninstall "$package/$innerPackage";
done;
fi; done;
My /usr/lib/node_modules
now contains only npm
and linked packages.
'IT박스' 카테고리의 다른 글
HashMap-첫 번째 키 값 얻기 (0) | 2020.08.26 |
---|---|
iOS 시뮬레이터에 붙여 넣기 텍스트 복사 (0) | 2020.08.26 |
자바 타임 스탬프-날짜가 2007 년 9 월 23 일인 타임 스탬프는 어떻게 만들 수 있습니까? (0) | 2020.08.26 |
div를 채우기 위해 배경 이미지를 늘리는 방법 (0) | 2020.08.26 |
명령 줄에서 Makefile에 인수를 전달하는 방법은 무엇입니까? (0) | 2020.08.25 |