본문 바로가기
플랫폼/Node.js

[Node.js] npm에서 yarn Berry 혹은 pnpm으로 마이그레이션

by minhyeok.lee 2024. 8. 2.
반응형

npm에서 yarn Berry 혹은 pnpm으로 마이그레이션

 


 

1. npm에서 yarn Berry로 마이그레이션

 

0. yarn 설치

sudo npm install -g yarn

 

1. yarn을 yarn berry로 변경

yarn set version berry

 

2. .yarnrc.yml에 nodeLinker 정보추가

nodeLinker: "node-modules"


3. package.lock.json, node_modules 제거

 

4. node_modules 생성

yarn install (yarn i)

 

- .yarn 디렉토리 하위에 cache가 생성되지 않는다면 .yarnrc.yml에 다음 옵션 추가

enableGlobalCache: false

 

- cache, releases디렉토리 및 install-state.gz파일에 변경사항 확인 및 ignore하는 파일(깃, 도커 등)들에 아래 내용 추가

.yarn/*
!.yarn/cache
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

 

5. .yarnrc.yml에서 nodeLinker 필드를 제거하거나 pnp로 설정 후 아래 명령어 실행

yarn install

 

추가로 VSC에서 사용하기 위해서는 Extension에서 ZipFS - a zip file system 설치 후 아래 명령어 실행

yarn dlx @yarnpkg/sdks vscode

 

.vscode 디렉토리에 extensions.json, .yarn 디렉토리에 sdks 디렉토리가 생성되었다면 성공

 

6. Dockerfile, package.json, workflow에 사용한 npm명령어를 yarn으로 변경

7. 마지막으로 아래 명령어로 마이그레이션이 잘되었는지 확인

yarn dev

2. npm에서 pnpm으로 마이그레이션

0. pnpm 설치

(sudo) npm install -g pnpm

 

1. 기존 lock file을 base로 해서 pnpm-lock.file을 만듬

pnpm import

 

2. package.lock.json, node_modules 제거

 

3. node_modules 생성

pnpm install (pnpm i)

 

4. Dockerfile, package.json, workflow에 사용한 npm명령어를 pnpm으로 변경

 

5. 마지막으로 아래 명령어로 마이그레이션이 잘되었는지 확인

pnpm dev

 

 

3. 에러 발생 시

1. 설치 후 일부 패키지의 버전이 업그레이드되면서 예상치 못한 버그 발생 가능

2. 의심 가는 라이브러리가 있으면 기존 파일에 사용되던 특정 버전으로 되돌린 후 다시 로컬에서 테스트

반응형

댓글