개발/Front-End

NPM 인스톨 에러 --force, --legacy-peer-deps

날고싶은병아리 2022. 5. 24. 10:45

작년인가 재작년인가 세팅한 프로젝트와 동일한 구성으로 새로운 프로젝트를 만들 일이 생겼다.

 

밑바닥부터 새로 만들기에는 열정과 연봉이 부족하여 기존 프로젝트를 복사했다.

그리고

npm i

실행.

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: pug-loader@2.4.0
npm ERR! Found: pug@3.0.2
npm ERR! node_modules/pug
npm ERR!   dev pug@"^3.0.2" from the root project
npm ERR!   peer pug@"^2.0.0 || ^3.0.0" from pug-plain-loader@1.1.0
npm ERR!   node_modules/pug-plain-loader
npm ERR!     dev pug-plain-loader@"^1.1.0" from the root project  
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer pug@"^2.0.0" from pug-loader@2.4.0
npm ERR! node_modules/pug-loader
npm ERR!   dev pug-loader@"^2.4.0" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: pug@2.0.4
npm ERR! node_modules/pug
npm ERR!   peer pug@"^2.0.0" from pug-loader@2.4.0
npm ERR!   node_modules/pug-loader
npm ERR!     dev pug-loader@"^2.4.0" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

뿅! 에러 발생.

 

에러를 요약하자면 pug-plain-loader 1.1.0 버전과 pug-loader 2.4.0 버전은 pug 2.0.0 버전을 참조하지만,

현재 프로젝트에는 pug 가 3.0.2 버전이라는 것.

 

맨 아래 메시지를 주목하자.

npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

대충 읽어보자면 dependency conflict, 즉 참조가 꼬였다는 소리.

해결하려면 --force 또는 --legacy-peer-deps 옵션을 추가하라고 한다.

 

 

두 개의 차이가 뭘까?

찾아보니 npm 7 버전부터 생긴 이슈라고 되어있다.

 

npm 7 is now generally available! | The GitHub Blog

We’re announcing version 7 of the npm CLI is now generally available.

github.blog

--force: bypass the conflict

--legacy-peer-deps: ignore peer dependencies entirely

 

--force 는 충돌을 우회하고 --legacy-peer-deps 는 충돌을 무시한다고 한다.

 

 

npm: When to use `--force` and `--legacy-peer-deps`

I'm new to npm and am trying to understand how recreating the node_modules directory for deployment works. We're using npm ci instead of npm install to ensure a clean slate during deployment. Howev...

stackoverflow.com

조금 더 찾아보자.

 

요약하자면.

--force 는 필요한 경우 패키지 의존성을 위해 추가적인 패키지를 설치한다.

--legacy-peer-deps 는 그냥 무시하고 설치한다.

 

참고로 npm 6 까지는 --legacy-peer-deps 와 비슷한 방식으로 자동 설치되었으나 npm 7 부터는 우선 차단부터 시킨다고 한다.

 

그럼 --legacy-peer-deps 를 날려보자.

npm i --legacy-peer-deps

발사!

npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.      
npm WARN deprecated popper.js@1.16.1: You can find the new Popper v2 at @popperjs/core, this package is dedicated to the legacy v1

히히! 에러 발사!

 

어림없지!

 

--force 를 날려봐도 마찬가지.

그럴 땐 마찬가지로 캐시를 날려버리자.

npm cache clear --force

그리고 --legacy-peer-deps 로 다시 설치.

npm notice Beginning October 4, 2021, all connections to the npm registry - including for package installation - must use TLS 1.2 or higher. You are currently using plaintext http to connect. Please visit the GitHub blog for more information: https://github.blog/2021-08-23-npm-registry-deprecating-tls-1-0-tls-1-1/
npm notice Beginning October 4, 2021, all connections to the npm registry - including for package installation - must use TLS 1.2 or higher. You are currently using plaintext http to connect. Please visit the GitHub blog for more information: https://github.blog/2021-08-23-npm-registry-deprecating-tls-1-0-tls-1-1/
npm WARN deprecated @stylelint/postcss-markdown@0.36.2: Use the original unforked package instead: postcss-markdown
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated popper.js@1.16.1: You can find the new Popper v2 at @popperjs/core, this package is dedicated to the legacy v1

added 1446 packages in 43s

157 packages are looking for funding
  run `npm fund` for details

감사합니다.

오늘도 밥벌이를 했어요.

 

이도저도 안되면 yarn 을 씁시다.