Yarn Classic vs Yarn Berry (v2+)
You'll learn how Yarn's architecture fundamentally changed between version 1.x (Classic) and version 2+ (Berry), making them almost different tools entirely.
The Great Architectural Divide
When Yarn released version 2 in 2020, it wasn't just an update—it was a complete reimagining of how package management could work. While Yarn Classic (1.x) follows the traditional node_modules approach similar to npm, Yarn Berry (2+) introduced revolutionary concepts that break from decades of JavaScript convention.
Yarn Classic: The Familiar Territory
Yarn Classic operates like npm: it creates a node_modules directory filled with nested folders containing your dependencies. It introduced improvements like faster installs, better lockfiles (yarn.lock), and deterministic dependency resolution, but the core model remained unchanged. Think of it as a well-organized library where each book occupies physical shelf space.
Yarn Berry: The Radical Rethink
Yarn Berry's headline feature is Plug'n'Play (PnP): instead of extracting packages into node_modules, it keeps dependencies as .zip files in a .yarn/cache directory and uses a single .pnp.cjs file to resolve imports. This is like replacing your physical library with a digital catalog—no unpacking required, just instant lookups.
Other Berry innovations include:
- Zero-installs: Commit the cache to version control for instant setup
- Workspaces 2.0: Enhanced monorepo management
- Constraints: Enforce policy across dependencies
- Built-in TypeScript support
The trade-off? Many tools expect node_modules to exist, causing compatibility headaches. Berry offers a nodeLinker: "node-modules" option to fall back, but you lose PnP's benefits.
Key Takeaway: Yarn Classic is an improved npm alternative using traditional architecture, while Yarn Berry fundamentally reimagines package management with Plug'n'Play, offering performance gains at the cost of ecosystem compatibility challenges.