IT/기타

[npm] npm install할 때 unable to resolve dependency tree 오류

Tesseractjh 2022. 8. 1. 22:36

 

 

 

요즘 npm intsall을 하면 이런 에러를 자주 마주하게 된다. 원인은 2021년 2월 출시된 npm 7버전부터 추가된 peerDependencies를 자동으로 설치하는 기능 때문이다. peerDependencies를 자동으로 설치할 때, 이미 설치되어 있는 의존성(direct dependencies of the root project)과 동일하지만 버전이 다른 peerDependencies가 존재하면 충돌이 일어나서 위와 같은 에러가 나게 된다.

 

$ npm install @craco/craco --legacy-peer-deps
$ npm install @craco/craco --force

 

해결하려면 npm install 모듈명 명령어 뒤에 --legacy-peer-deps 또는 --force를 추가해주면 된다. --legacy-peer-deps는 npm 4 ~ 6버전 때처럼 peerDependencies를 자동으로 설치하지 않도록 설정하는 것이고, --force는 충돌이 일어난 peerDependecies를 강제로 설치하도록 설정하는 것이다.

 

둘 중 어떤 것을 택해야 하는지는 의견이 분분한 것 같다.

 

 

참고자료

https://velog.io/@yonyas/Fix-the-upstream-dependency-conflict-installing-NPM-packages-%EC%97%90%EB%9F%AC-%ED%95%B4%EA%B2%B0%EA%B8%B0

 

npm install `--force` and `--legacy-peer-deps` 차이점

참고 https://stackoverflow.com/questions/66020820/npm-when-to-use-force-and-legacy-peer-deps

velog.io

https://velog.io/@gth1123/npm-cli-flag-force-and-legacy-peer-deps

 

npm cli flag: `--force` and `--legacy-peer-deps`

inflearn의 drag and drop을 만들기 위해 가장 비슷한 sortablejs 라이브러리를 사용하기위해 설치하려는 중 에러가 발생했다.내가 설치한 CRA에서 자동으로 설치된 react의 버전은 17.0.2인데 라이브러리에

velog.io

https://stackoverflow.com/questions/66239691/what-does-npm-install-legacy-peer-deps-do-exactly-when-is-it-recommended-wh

 

What does npm install --legacy-peer-deps do exactly? When is it recommended / What's a potential use case?

Just ran into this error: npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! While resolving: nexttwin@0.1.0 npm ERR! Found: react@17.0.1 npm ERR! node_mo...

stackoverflow.com