Skip to content

Step-by-step

Note that those commands only need to be run once for the whole project and will automatically take effect for all your contributors as soon as they pull the branch, as long as they have Corepack enabled.

  1. Make sure you’re using Node 18+
  2. Run corepack enable to activate Corepack
  3. Go into your project directory
  4. Run yarn set version berry
  5. Convert your .npmrc and .yarnrc files into .yarnrc.yml (details here)
  6. Run yarn install to migrate the lockfile
  7. Commit all changes

Good, you should now have a working Yarn install! Some things might still require some adjustments in your CI scripts (for example the deprecation of arbitrary pre/post-scripts, or the renaming of --frozen-lockfile into yarn install ! --immutable), but at least we have a working project.

Update your configuration to the new settings

Section titled “Update your configuration to the new settings”

Modern uses a different style of configuration files than Classic. While mostly invisible for the lockfile (because we convert them on the fly), it might cause issues if you rely on .npmrc or .yarnrc files.

  • Yarn Modern now uses .yarnrc.yml. Any other file is now ignored - this includes .npmrc.
  • As evidenced by the new file extension, the Yarnrc files are now to be written in YAML.

Most configuration keys have also been renamed to be more consistent. The comprehensive list of available settings can be found on the .yarnrc.yml dedicated documentation, but here are some important ones:

Some changes were made to how lifecycle scripts work in order to clarify their purpose and remove confusing behaviors. One such change is that custom pre and post scripts are no longer supported. As a result, rewrite:

{
"scripts": {
"prestart": "do-something",
"start": "http-server"
}
}

Into:

{
"scripts": {
"prestart": "do-something",
"start": "yarn prestart && http-server"
}
}

Yarn focuses on project management, and managing system-wide packages was deemed to be outside of our scope. As a result, yarn global got removed and needs to be replaced by yarn dlx to run one off scripts.

The bundleDependencies field (or bundledDependencies) is an artifact of the past that used to let you define a set of packages that would be stored as-is within the package archive, node_modules and all. This feature has many problems:

  • It uses node_modules, which doesn’t exist under Plug’n’Play installs.
  • It encodes the hoisting inside the package, messing with the hoisting from other packages.

So how to replace them? There are different ways:

  • If you need to patch a package, just fork it or reference it through the file: protocol (it’s perfectly fine even for transitive dependencies to use this protocol). The portal: and patch: protocols are also options, although they’ll only work for Yarn consumers.

  • If you need to ship a package to your customers as a standalone (no dependencies), bundle it yourself using Esbuild, Webpack, Rollup, or similar tools.

The nohoist setting from Yarn Classic was built for React Native in order to support workspaces, but the way it worked (through glob patterns) was causing a lot of bugs and confusion, no one being really sure which patterns needed to be set. As a result, we’ve simplified this feature in order to only support three identified patterns.

If you were using nohoist, we recommend you remove it from your manifest configuration and instead set nmHoistingLimits in your .yarnrc.yml file:

nmHoistingLimits: workspaces
Yarn Classic (1.x)Yarn Modern
yarn audityarn npm audit
yarn createyarn dlx create-NAME
yarn globalyarn dlx (Read more)
yarn infoyarn npm info
yarn listyarn info -AR (yarn info ! --json?)
yarn loginyarn npm login
yarn logoutyarn npm logout
yarn outdatedyarn upgrade-interactive (Read more)
yarn publishyarn npm publish
yarn upgradeyarn up (note: updates all workspaces)
yarn install --productionyarn workspaces focus --all --production
Yarn Classic (1.x)
Notes
yarn checkCache integrity is now checked on regular installs - Read more
yarn importFirst import to Classic, then migrate to Yarn Modern
yarn licensesPerfect use case for plugins - Read more
yarn versionsUse yarn --version and node -p process.versions

Those features simply haven’t been implemented yet. Help welcome!

Yarn Classic (1.x)
Notes
yarn ownerWill eventually be available as yarn npm owner
yarn teamWill eventually be available as yarn npm team