[NodeJS] npm install ( --force | --legacy-peer-deps )

이애진·2022년 12월 12일

Node

목록 보기
12/12
post-thumbnail

1. 배경 및 원인

@toast-ui/react-editor 라이브러리를 설치하다 아래와 같은 오류를 만났다

의존성 트리 충돌이 났다는 내용이다
@toast-ui/react-editor@3.2.2는 react 17버전을 사용하고 있기 때문에 맞춰서 사용하라는 에러이다
충돌을 해결하려면 --force--legacy-peer-deps 옵션을 사용하여 설치하라고 알려준다

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.

npm이 버전 7로 업데이트 되면서 peer dependencies 자동 설치가 생겼다
이전 4-6 버전에서는 경고만 표시했지만 7 버전에서는 충돌이 있는 경우 에러로 판단해 설치를 중단한다


2. peer dependencies?

실제로 패키지에서 require, import 하지 않지만, 특정 라이브러리나 툴의 호환성을 필요로 할 경우 명시하는 dependency이다
=> 패키지가 요구하는 패키지


3. 해결

You have the option to retry with --force to bypass the conflict or --legacy-peer-deps command to ignore peer dependencies entirely (this behavior is similar to versions 4-6).

--force는 package-lock.json에 의존 버전을 추가적으로 설치하고, --legacy-peer-deps는 의존성이 맞지 않아도 일단 설치한다
--force를 우선으로 해보고 에러나면 --legacy-peer-deps로 설치 진행한다


ref

profile
Frontend Developer

0개의 댓글