Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

Update yarn to 4.11.0 #10719

@tommoor

Description

@tommoor

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.yml with the yarnPath setting
  • Update the packageManager field in package.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 upgradeyarn up
  • yarn upgrade-interactiveyarn upgrade-interactive
  • yarn install --frozen-lockfileyarn install --immutable

7. Verify the Installation

yarn --version

Should output: 4.11.0


Important Considerations

  1. Migration complexity: Moving from Yarn 1 to Yarn 4 is a major upgrade. Consider testing thoroughly in a branch first.

  2. CI/CD pipelines: Update any CI configuration files that reference yarn installation or use --frozen-lockfile (change to --immutable).

  3. patch-package: The project uses patch-package (see postinstall script). Yarn Berry has built-in patching via yarn patch. You may want to migrate patches to the native format.

  4. Plugins: Some Yarn Classic plugins may not work. Check compatibility.

  5. 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
    
  6. Implement npmMinimalAgeGate setting with a 24h cooldown

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions