Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Corepack does not use the yarn version set in package.json

Erroryarn --version prints a different version than package.json packageManager

Short answer

Corepack only picks the yarn version from the packageManager field when its own yarn shim is the one that runs. Run corepack enable, write the field as yarn@x.y.z with an exact version, and change versions with corepack use yarn@<version> rather than editing around it.

  • Applies to Node.js 22, Node.js 24, Corepack, Yarn
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Compare the version Corepack would use with the version that actually runs, and see which yarn binary is first on the path.

    grep packageManager package.json
    which yarn
    yarn --version
  2. 2Match what you see, then jump to its fix

    1. 1which yarn points to a global install, not a Corepack shimCorepack is not enabled, so its yarn shim is not on the pathFix
    2. 2Field reads yarn@4 or yarn@latestThe packageManager value is not an exact versionFix
    3. 3COREPACK_ENABLE_STRICT=0 is set, and a different package manager runs without an errorStrict checking is turned off in the environmentFix
    4. 4The pinned version is older than the release you wantYou want a newer version of the same major lineFix

What does the error look like?

  • yarn --version prints a different version than package.json packageManager
  • the packageManager field is ignored
  • yarn version cannot be changed in a Corepack project

Cause 1 of 4

Corepack is not enabled, so its yarn shim is not on the path

1Check

The Corepack docs say corepack enable installs the Yarn and pnpm binaries on your path. If you never ran it, the yarn you call is some other yarn.

which -a yarn

2Fix

Enable Corepack so it creates the yarn shim.

corepack enable
hash -r

3Verify

yarn now prints the version from packageManager.

yarn --version

Confirmed by github.com

Did this fix it?

Cause 2 of 4

The packageManager value is not an exact version

1Check

The docs say packageManager@x.y.z is required; the hash after it is optional. A range or a tag is not an exact version.

grep -n packageManager package.json

2Fix

Let Corepack write the field for you. corepack use fetches the latest release matching the version you give, saves it into package.json and runs an install.

corepack use yarn@4

3Verify

package.json holds the full version and yarn matches it.

grep packageManager package.json
yarn --version

Confirmed by github.com

Did this fix it?

Cause 3 of 4

Strict checking is turned off in the environment

1Check

Setting COREPACK_ENABLE_STRICT to 0 stops Corepack from throwing when the package manager does not match the project's. Look for it in your shell profile and CI.

env | grep COREPACK

2Fix

Unset the variable so Corepack tells you when the wrong manager is used, then run the command again with the manager the project names.

unset COREPACK_ENABLE_STRICT
yarn install

3Verify

The variable is gone from the environment.

env | grep COREPACK

Confirmed by github.com

Did this fix it?

Cause 4 of 4

You want a newer version of the same major line

1Check

corepack up retrieves the latest version of the current major line for the project's manager and updates the project. Check the pinned version first.

grep packageManager package.json

2Fix

Update through Corepack instead of changing the number by hand.

corepack up

3Verify

The packageManager field shows the new version.

grep packageManager package.json
yarn --version

Confirmed by github.com

Did this fix it?

How do I stop it coming back?

  • Commit the packageManager field with an exact version so every machine and CI job uses the same yarn.
  • Run corepack enable in your CI image and on new machines before the first install.
  • Change the version only with corepack use or corepack up.
  • Do not set COREPACK_ENABLE_STRICT=0 globally.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

ng serve says it cannot determine the project or target

Cannot determine project for command.

The Angular CLI looked through angular.json for a project that defines the target you asked for (serve, build, test) and found none, or found several and could not pick one.

3 causes, each with a fix

Back end

ng serve cannot find the dev-server builder package

Could not find the implementation for builder @angular/build:dev-server

The builder named in angular.json (for example @angular-devkit/build-angular:dev-server) is looked up as an npm package starting from the workspace root.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.