ect

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

개발 공부 2024. 8. 26. 10:48

 

npm install을 할 때 "unable to resolve dependency tree"에러가 발생하면서

npm 설치가 안될 때가 있다.

이런 경우 npm 이 패키지간의 의존성 충돌을 해결하지 못했을 때 발생한다.

 

나 같은 경우는 quill 패키지의 2.0.2버전이 프로젝트의 루트에서 사용되고 있지만,

@xeger/quill-image-actions 패키지가 quill의 1.3.6버전을 요구하고 있어 문제가 발생한다.

 

이런 에러가 발생할 경우

npm install --force 이나 npm install --legacy-peer-deps 를 사용하면 되는데

둘의 차이점을 알아보도록 하자

 

npm v7에서 달라진 점

2021년 2월 npm 7버전이 나왔는데

Automatically installing peer dependencies is an exciting new feature introduced in npm 7. In previous versions of npm (4-6), peer dependencies conflicts presented a warning that versions were not compatible, but would still install dependencies without an error. npm 7 will block installations if an upstream dependency conflict is present that cannot be automatically resolved. 
- in npm github blog

 

npm 4~6버전에서는 peer dependencies의 버전이 달라 충돌할 경우 경고만 뜨고 설치는 됐다.

근데 7부터는 설치가 되지 않는다.

 

  • --legacy-peer-deps: ignore all peerDependencies when installing, in the style of npm version 4 through version 6.
    • 설치 시 모든 peerDependencies를 무시한다. npm4~6 버전 처럼
  • --strict-peer-deps: fail and abort the install process for any conflicting peerDependencies when encountered. By default, npm will only crash for peerDependencies conflicts caused by the direct dependencies of the root project.
    • peerDependencies를 충돌이 생기면 설치가 중단된다. 기본적으로 npm은 루트 프로젝트의 직접적인 종속성으로 인한 peerDependencies 충돌에 대해서만 충돌합니다.

 

--force를 사용하면 package-lock.json에 몇가지의 다른 의존 버전들을 추가한다.

(peerDependencies가 루트 프로젝트에 설치되도록 허용)

--legacy-peer-deps는 npm v7에서 제공하는 peerDependencies가 자동으로 설치되는 기능을 사용하지 않음

 

결론 : --force 를 먼저 사용해보고 안 되면 --legacy-peer-deps 사용하기

 

참고 ) 

 

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

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

velog.io

 

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

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

velog.io