Docs/Migrations/Migrating from Yarn Classic

Migrating from Yarn Classic

Move a Yarn 1.x project to Yarn 6 while keeping the versions it was locked to.

Yarn 6 can read the lockfiles generated by Yarn Classic (1.x), so there’s no need to go through Yarn 4 first. Once Yarn Switch points your project to Yarn 6 (for example by running yarn set version zpm), run a regular install and commit the files it changes:

yarn install

During this first install, Yarn reads your Yarn 1.x yarn.lock and keeps the exact version it recorded for each package coming from an npm registry (including scoped packages and npm: aliases), so your dependency tree doesn’t change. The lockfile is then rewritten in the Yarn 6 format.

NOTE

The migration needs to rewrite the lockfile, so it can’t happen during an immutable install: yarn install --immutable (which is the default on most CI providers) will fail until the migrated lockfile has been committed.

Settings added to .yarnrc.yml#

Some Yarn 6 defaults would change how your project installs, so the first install adds the following settings to your project .yarnrc.yml and lists them in its output:

SettingValueWhy
nodeLinkernode-modulesYarn Classic projects expect a node_modules folder
approvedGitRepositories["**"]Yarn Classic fetched git dependencies from any repository
enableScriptstrueYarn Classic ran the build scripts of dependencies
npmMinimalAgeGate0sYarn Classic installed freshly published versions right away

Settings you already defined in the project .yarnrc.yml, the home .yarnrc.yml, or through their environment variable (for example YARN_NODE_LINKER) are left untouched. Once your project works with Yarn 6, you can remove them to opt into the stricter defaults described in the breaking changes, and switch to Plug’n’Play.

Under the migration mode, the root lockfile stays in the Yarn Classic format, so Yarn uses those settings for every command without writing them.

What changes#

  • Some entries can’t be imported: git dependencies, packages installed from an arbitrary url, and entries whose version was overridden through the resolutions field. Yarn prints a warning for each of them and resolves them again.

  • Yarn doesn’t read the .npmrc and .yarnrc files. Packages are always fetched from the registry configured through npmRegistryServer and npmScopes, even if your lockfile references other urls; Yarn warns you when your lockfile was generated against a registry that isn’t the one it’s configured to use.

  • Yarn Classic checksums aren’t reused; Yarn computes its own checksums when it first downloads the packages.