Yarn 1 entered maintenance mode in January 2020 and is effectively dead. Upgrading production Next.js repos to Yarn 4 roughly cut our install times in half (yarn install --immutable dropped from ~1m 45s to ~47s, and parallel multi-service builds fell from ~3m 52s to ~1m 58s).
Key migration steps
- Keep
nodeLinker: node-modulesfirst: SetnodeLinker: node-modulesandenableTelemetry: falsein.yarnrc.ymlso Docker builds, debuggers, and Next.js tooling keep working predictably before you ever consider Plug'n'Play. - Pin via Corepack: Run
yarn set version 4.6.0sopackage.jsonrecords"packageManager": "yarn@4.6.0". - Update
.gitignoreand.dockerignore: Ignore.yarnandnode_modulesso native host installs and Docker containers can live side by side. - Enable Corepack in Docker and CI: Replace old apt Yarn 1 installs with
corepack enable && corepack prepare yarn@4.6.0in base images, and addcorepack enableto CI jobs using stock Node images. Yarn 4 parallelizes harder too, soyarn installjobs may need higher CI memory limits.
CLI surprises coming from Yarn 1
- Upgrading packages:
yarn up <pkg>jumps to the latest major (for example bumpingnextfrom 14 to 16), whileyarn up -R <pkg>acts like Yarn 1'syarn upgradeand stays within the semver range. Plainyarnupdates lockfile patches within ranges. yarn linkchanged completely: Instead of runningyarn linkin the package andyarn link @scope/pkgin the app, Yarn 4 takes relative paths directly (yarn link ../pkg-one ../pkg-two). It also writesportal:resolutions intopackage.jsonandyarn.lock, which is annoying because you have to be careful not to commit those local edits.- Stricter dependency resolution: Yarn 4 catches missing peer and dev dependencies (like explicit
react-isor alignedreactandreact-domversions) that Yarn 1 silently hoisted.