전체 치트시트프런트엔드 개발

yarn

Yarn 1.x (classic) / Yarn 4 (berry)

매일 쓰는 Yarn CLI 명령어 빠른 참조(Yarn Classic 1.x와 Yarn Berry 2/3/4 모두) — install / add / remove / run / workspaces, lockfile, Plug'n'Play, Berry 설정 — 자주 쓰는 옵션과 실전 예시까지 함께 정리했습니다.

명령어 33개

설치 (Classic 1.x)

yarn install

`package.json`의 모든 의존성을 설치해 `node_modules`와 `yarn.lock`을 생성/갱신합니다.

--frozen-lockfile lock이 바뀌면 실패(CI); --production / --prod devDeps 생략; --no-progress; --silent

yarn install --frozen-lockfile
yarn install --frozen-lockfile

`yarn.lock`이 `package.json`과 정확히 일치할 때만 설치합니다. CI에서 재현 가능한 빌드를 보장할 때 사용합니다.

yarn install --frozen-lockfile

설치 (Berry)

yarn install

Berry 기본 동작: `.yarnrc.yml`에 `nodeLinker: pnp`가 있으면 Plug'n'Play를 사용하고, 아니면 `node_modules`로 폴백합니다. 캐시는 `.yarn/cache`에 저장됩니다.

--immutable lockfile 변동 시 실패(Berry의 --frozen-lockfile 동등); --inline-builds; --mode=update-lockfile

yarn install --immutable
yarn set version <version>

프로젝트의 Yarn 바이너리를 전환합니다. 자주 쓰는 예: `yarn set version stable`, `yarn set version 4.0.2`, `yarn set version classic`.

yarn set version stable

의존성 추가

yarn add <pkg>

런타임 의존성을 추가하고 `package.json` + lockfile에 기록합니다. Classic은 `dependencies`, Berry도 동일합니다.

<pkg>@<version|range>; --dev / -D; --exact / -E; --optional / -O; --peer

yarn add lodash && yarn add -D typescript@^5 vitest
yarn add -D <pkg>

`devDependencies`에 추가합니다.

yarn add -D typescript @types/node eslint
yarn add <pkg>@<version>

특정 버전, dist-tag(`@latest`, `@next`, `@canary`), 또는 git URL을 설치합니다.

yarn add [email protected] && yarn add next@latest
yarn global add <pkg>

툴을 글로벌로 설치합니다(Classic 1.x). Berry는 일회성 바이너리에 `yarn dlx`를 쓰고, 글로벌 툴은 `corepack`을 권장합니다.

yarn global add typescript

제거

yarn remove <pkg>

`node_modules`와 해당 `dependencies` / `devDependencies` 섹션에서 패키지를 제거합니다.

yarn remove lodash && yarn remove -D @types/node

업데이트

yarn upgrade

현재 semver 범위 안에서 모든 의존성을 업그레이드합니다. `yarn upgrade --latest`는 최신 사용 가능 릴리스로 점프하고 범위를 다시 씁니다.

--latest; --pattern <glob>; --caret; --exact; -i / --interactive

yarn upgrade && yarn upgrade eslint --latest
yarn upgrade <pkg>@<version>

한 패키지를 특정 버전으로 업그레이드합니다.

yarn upgrade [email protected]

스크립트 실행

yarn run <script>

`package.json`의 스크립트를 실행합니다. `yarn test`, `yarn start`, `yarn build`는 축약형입니다.

-- <args> 스크립트로 인수 전달

yarn run build -- --mode production
yarn <script>

`yarn run <script>`와 동일합니다 — `run` 키워드 없이 정의된 스크립트를 이름으로 호출합니다.

yarn test && yarn lint:fix
yarn dlx <pkg> [args]

로컬에 설치하지 않고 패키지 바이너리를 즉시 실행합니다(Berry의 `npx` 동등). `~/.yarn/berry/cache`에 캐시됩니다.

-p / --package 패키지 선택; -q / --quiet

yarn dlx create-vite my-app --template vue

워크스페이스

yarn workspaces add <pkg>

모노레포 워크스페이스의 루트에 의존성을 추가합니다(1.x).

yarn workspaces add typescript -D
yarn workspace <ws> add <pkg>

모노레포의 단일 명명 워크스페이스에 의존성을 추가합니다.

yarn workspace @myorg/web add react && yarn workspace @myorg/api add -D vitest
yarn workspaces run <script>

모든 워크스페이스에서 스크립트를 실행합니다. `yarn workspaces foreach run <script>`(Berry)는 동시성과 토폴로지 순서를 지원합니다.

--parallel; --topological; --continue; --interlaced

yarn workspaces foreach run build --topological --parallel

검사

yarn list

의존성 트리를 출력합니다. `--pattern <regex>`로 필터링하고, `--depth 0`은 직접 의존성만 보여줍니다.

--depth=N; --pattern; --json

yarn list --depth=0 && yarn list --pattern "^react$"
yarn why <pkg>

패키지가 왜 설치되었는지, 즉 어떤 의존성 체인을 통해 들어왔는지 설명합니다.

yarn why react && yarn why @types/node
yarn info <pkg>

패키지의 레지스트리 메타데이터를 출력합니다 — 버전, 의존성, dist-tags, readme 발췌. `npm view`와 거의 동등합니다.

<pkg>@<version>; <pkg> readme; <pkg> dependencies

yarn info react dist-tags && yarn info lodash versions
yarn licenses list

의존성 트리의 모든 라이선스(SPDX 식별자 + 작성자)를 나열합니다. 라이선스 컴플라이언스 검토에 유용합니다.

yarn licenses list

Berry 설정

yarn config set <key> <value>

`.yarnrc.yml`(Berry)에 설정 항목을 기록합니다. 자주 쓰는 키: `nodeLinker`, `npmRegistryServer`, `enableTelemetry`, `yarnPath`.

yarn config set nodeLinker node-modules && yarn config set enableTelemetry false
yarn config get <key>

단일 설정 항목을 읽습니다.

yarn config get nodeLinker

캐시

yarn cache clean

Yarn 캐시를 비웁니다(Classic: `~/.yarn-cache`, Berry: `.yarn/cache`).

yarn cache clean
yarn cache dir

캐시 디렉터리 경로를 출력합니다.

yarn cache dir

Lockfile

yarn import

Berry 전용 — npm의 `package-lock.json`을 Yarn의 lockfile 형식으로 가져옵니다.

yarn import
yarn constraints

Berry 전용 — `constraints.pro`에 Prolog로 작성된 프로젝트 전체 의존성 규칙을 강제합니다(예: 모든 워크스페이스가 같은 React 버전을 사용해야 함).

yarn constraints

감사

yarn npm audit

Berry — npm 레지스트리의 권고 피드를 프록시합니다. lockfile의 취약점을 보고합니다.

--severity info|low|moderate|high|critical; --json

yarn npm audit --severity high

기타

yarn version

현재 Yarn 버전을 출력합니다(Classic과 Berry 모두에서 동작).

yarn version
yarn init

`package.json`을 인터랙티브하게 생성하며, `-y`로 기본값을 수락합니다.

-y 기본값 수락; -p / --private 비공개로 표시

yarn init -y
yarn pack

현재 패키지를 게시하지 않고 tarball로 묶습니다 — 오프라인 배포에 유용합니다.

--filename; --pack-destination <dir>

yarn pack --filename my-pkg.tgz

Plug'n'Play (Berry)

yarn unplug <pkg>

PnP zip 저장소에서 한 패키지를 일반 `node_modules/<pkg>`로 추출해 구식 방식으로 require할 수 있게 합니다(비호환 도구용 워크어라운드).

yarn unplug react && yarn install
yarn rebuild

현재 Node ABI용으로 네이티브 애드온을 다시 컴파일합니다. PnP 하에서 네이티브 의존성을 가진 패키지에 Berry가 필요로 하는 단계입니다.

yarn rebuild

관련 명령어 치트시트

Yarn 소개

Yarn은 Facebook(Meta)이 2016년 10월에 npm보다 빠르고 결정적인 대안으로 사용와 함께 출시했고, Google, Exponent, Tilde의 기여가 있었습니다. 원래 1.x 라인은 지금 "Yarn Classic"이라 불리며 유지보수 모드입니다. 활성 라인은 "Yarn Berry"이며(2020년 2.0, 2021년 3.0, 2022년 4.0, 현재 5.x), Yarn Berry는 Node가 내장된 4MB 단일 바이너리 `yarn`, npx 대체인 `yarn dlx`, `yarn workspaces`, 그리고 Plug'n'Play(`yarn install --immutable`과 `.pnp.cjs`)를 제공합니다. Plug'n'Play는 `node_modules`를 설치하지 않고 단일 zip 저장소에서 패키지를 해석하는 논쟁적인 기본 동작입니다. Berry는 `yarnrc.yml`(YAML)로 설정되며, Classic의 `yarnrc` ini와는 다릅니다. 두 라인은 같은 머신에 공존할 수 있습니다 — `yarn set version classic`과 `yarn set version berry`로 바이너리를 전환합니다. Yarn은 설치 속도가 npm보다 빠르고(병렬 + 캐시), 모노레포 정책용 `workspaces` / `constraints`를 지원하며, 내장된 `yarn why` / `yarn licenses` 인트로스펙션을 갖추고 있습니다. Meta로 데이터가 전송되지는 않으며, Yarn은 BSD-2-Clause의 독립 OSS입니다.

치트시트 버전 1.0.0