[yarn] 모듈 버전 관리

JJeong·2021년 11월 30일
0

배경

젠킨스 배포가 실패했고 다음과 같은 콘솔 에러 메시지가 떴다.

"패키지를 찾지 못했으니 설치되어야 합니다."
우리 팀 젠킨스의 셀 스크립트는 이러하므로

npm install 로 정상 설치가 되지 않았다는 뜻이다.


원인

해당 패키지의 버전을 낮춰보는 방향으로 해결 가닥을 잡았다.

하지만 패키지는 이미 적합한 버전(1.0.6)으로 지정되어 있는 것 같았다...


해결

2) 캐럿(^)
해당 패캐지의 마이너, 패치 변경을 허용하겠다는 의미입니다.

~2.6.11 은 >= 2.6.11 이상, < 3.0.0 미만 과 같은 의미입니다.

즉, 3.0.0 미만의 마이너, 패치 변경을 허용하겠다는 의미입니다.

따라서, 이 패키지의 가장 최신 버전인 1.1.2가 자동으로 설치되었던 것이다.
앞에 캐럿을 빼고 yarn.lock을 지우고 다시 설치하자 정상적으로 작동되었다.
해결! ✨


+보너스

Yarn creates a yarn.lock file after you perform a yarn install.
Should this be committed to the repository or ignored? What is it for?

yarn install 하면 그때마다 yarn.lock 파일이 만들어지는데 굳이 이 파일을 레포지토리에 올려야 해? 어떤 목적으로?

Why is it for?
The npm client installs dependencies into the node_modules directory non-deterministically. This means that based on the order dependencies are installed, the structure of a node_modules directory could be different from one person to another. These differences can cause works on my machine bugs that take a long time to hunt down.

왜냐구?
npm은 의존성 문제를 해결할 때 node_modules 폴더의 순서를 결정짓지 않아. 이 말은 설치되는 순서에 따라 node_modules 폴더의 구조도 사람마다 다를 거라는 뜻이지. 이 차이가 해결하기 어려운 버그를 만들어내.

Yarn resolves these issues around versioning and non-determinism by using lock files and an install algorithm that is deterministic and reliable. These lock files lock the installed dependencies to a specific version and ensure that every install results in the exact same file structure in node_modules across all machines.

Yarn은 이런 불확실성과 버전 관련 문제를 lock 파일과 이와 관련하여 짜여진 설치 알고리즘으로 해결하고 있어. 이 lock 파일은 아주 특정한 버전을 설치할 수 있게 해주고, 매번 설치할 때마다 모든 기기에서 node_modules 폴더가 같은 파일 구조를 가질 수 있게 고정시키고 있어!

0개의 댓글