Yarn Workspaces

Yarn Workspaces and Choosing an Edition

Workspaces keep several interdependent packages in one repository with one lockfile (MERN Stack Development, Workspaces builds them with npm 2,036 ). Yarn Berry 11,798 adds the workspace: protocol: "take this dependency from the repository, never the registry." Split BookNest into packages/api and a small packages/catalog library under a root package.json with "workspaces": ["packages/*"]; the API declares "@booknest/catalog": "workspace:^", and each package has a test script that prints a price.

Listing workspaces and running a script in dependency orderShell
yarn workspaces list --json
yarn workspaces foreach --all --topological --verbose run test
Output
{"location":".","name":"booknest-monorepo"}
{"location":"packages/api","name":"@booknest/api"}
{"location":"packages/catalog","name":"@booknest/catalog"}
[@booknest/catalog]: $24.00
[@booknest/api]: $18.50
Done in 0s 231ms

--topological ran the catalog first because the API depends on it. On publish, Yarn rewrites workspace:^ into a real range such as ^1.0.0. pnpm 69,400 and Bun 73,307 accept the same protocol.

Keep Yarn Classic 11,798 only where a project already uses it; for new work, choose Berry. To migrate, pin Yarn 4 with corepack 3,816 use yarn@stable (Corepack), set nodeLinker: node-modules, run yarn install to convert the lockfile, and try PnP later as a separate step.