-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Description
Steps to Update Yarn to 4.11.0
1. Enable Corepack (if not already enabled)
Corepack is Node.js's built-in tool for managing package managers:
corepack enable
2. Set the Yarn Version
Run the following command in the project root to upgrade to Yarn 4.11.0:
yarn set version 4.11.0
This will:
- Download Yarn 4.11.0 to
.yarn/releases/yarn-4.11.0.cjs - Create or update
.yarnrc.ymlwith theyarnPathsetting - Update the
packageManagerfield inpackage.json
3. Configure .yarnrc.yml
After running yarn set version, you'll need to configure Yarn Berry. Create/edit .yarnrc.yml:
yarnPath: .yarn/releases/yarn-4.11.0.cjs
nodeLinker: node-modules
The nodeLinker: node-modules setting keeps the traditional node_modules folder structure (recommended for easier migration). Without it, Yarn Berry defaults to Plug'n'Play (PnP) which requires more configuration.
4. Update .gitignore
Add these entries to .gitignore:
# Yarn Berry
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
5. Remove Old Lockfile and Reinstall
rm -rf node_modules
rm yarn.lock
yarn install
This generates a new yarn.lock file in the Yarn Berry format.
6. Update Scripts (if needed)
Some Yarn Classic commands have changed in Yarn Berry:
yarn upgrade→yarn upyarn upgrade-interactive→yarn upgrade-interactiveyarn install --frozen-lockfile→yarn install --immutable
7. Verify the Installation
yarn --version
Should output: 4.11.0
Important Considerations
-
Migration complexity: Moving from Yarn 1 to Yarn 4 is a major upgrade. Consider testing thoroughly in a branch first.
-
CI/CD pipelines: Update any CI configuration files that reference yarn installation or use
--frozen-lockfile(change to--immutable). -
patch-package: The project uses
patch-package(seepostinstallscript). Yarn Berry has built-in patching viayarn patch. You may want to migrate patches to the native format. -
Plugins: Some Yarn Classic plugins may not work. Check compatibility.
-
Alternative - Stay on Yarn Classic: If you just want the latest Yarn 1.x, you can update to the latest Classic version instead:
yarn set version classic -
Implement
npmMinimalAgeGatesetting with a 24h cooldown