intermediate

Yarn

Understand Yarn classic and modern workflows, lockfiles, workspaces, and Plug and Play trade-offs.

Yarn spans multiple generations. Yarn Classic (v1) is common in older codebases; Modern Yarn (Berry, v2+) adds Plug'n'Play, constraints, zero-install, and stricter immutable installs. Interview answers must identify the project's Yarn generation first.

| Generation | Lockfile | Notable behavior | |------------|----------|------------------| | Classic v1 | `yarn.lock` | Hoisted `node_modules`, familiar to npm users | | Modern Berry | `yarn.lock` + `.yarn/` | PnP optional, zero-install, `yarn workspaces` |

					# Modern Yarn immutable CI install (conceptual)
yarn install --immutable
				

Workspaces coordinate multi-package repos. Plug'n'Play removes `node_modules` in favor of resolution maps—stricter and faster, but some tools need SDK shims.

On interviews: `yarn.lock` review, workspace commands, PnP trade-offs, zero-install cache trade-offs, and immutable install enforcement in CI.

Common pitfalls: advising Berry commands on a Classic repo; PnP without editor/SDK setup; assuming Yarn equals npm script semantics in all versions.

The trade-off is modern strictness and features versus migration cost from Classic ecosystems.

Checklist:

  • Identify Yarn major generation in the repo.
  • Explain PnP versus `node_modules` when relevant.
  • Use immutable installs in CI for Modern Yarn.
  • Document editor SDK setup for PnP teams.