Corepack does not use the yarn version set in package.json
yarn --version prints a different version than package.json packageManagerShort 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.
Fix it fast
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 --version2Match what you see, then jump to its fix
- 1
which yarn points to a global install, not a Corepack shimCorepack is not enabled, so its yarn shim is not on the pathFix - 2
Field reads yarn@4 or yarn@latestThe packageManager value is not an exact versionFix - 3
COREPACK_ENABLE_STRICT=0 is set, and a different package manager runs without an errorStrict checking is turned off in the environmentFix - 4
The pinned version is older than the release you wantYou want a newer version of the same major lineFix
- 1
What does the error look like?
yarn --version prints a different version than package.json packageManagerthe packageManager field is ignoredyarn 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 yarn2Fix
Enable Corepack so it creates the yarn shim.
corepack enable
hash -r3Verify
yarn now prints the version from packageManager.
yarn --versionConfirmed by github.com
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.json2Fix
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@43Verify
package.json holds the full version and yarn matches it.
grep packageManager package.json
yarn --versionConfirmed by github.com
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 COREPACK2Fix
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 install3Verify
The variable is gone from the environment.
env | grep COREPACKConfirmed by github.com
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.json2Fix
Update through Corepack instead of changing the number by hand.
corepack up3Verify
The packageManager field shows the new version.
grep packageManager package.json
yarn --versionConfirmed by github.com
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 fixBack end
ng fails with Cannot find module @angular/cli/bin/ng
Cannot find module '@angular/cli/bin/ng'
The ng command is the entry point to the Angular CLI package.
2 causes, each with a fixBack end
Angular app shows 'Cannot GET /' when served by a Node.js server
Cannot GET /dashboard
Cannot GET / is Express saying no route or file matches the request.
3 causes, each with a fixBack 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 fixBack end
Angular build says it cannot resolve '@angular/localize/init'
Can't resolve '@angular/localize/init' in '/usr/src/app/src'
The build imports @angular/localize, and that package is not in node_modules.
2 causes, each with a fixBack end
The command npm run build -- --prod exited with code 1 (Angular)
The command "npm run build -- --prod" exited with code 1
Exit code 1 only says the build failed; the real message is above it.
2 causes, each with a fix