Skip to content

Instantly share code, notes, and snippets.

@basperheim
Created December 22, 2025 20:44
Show Gist options
  • Select an option

  • Save basperheim/02e6ad40ace07b21f288d03cbf6c3f82 to your computer and use it in GitHub Desktop.

Select an option

Save basperheim/02e6ad40ace07b21f288d03cbf6c3f82 to your computer and use it in GitHub Desktop.
Fixing "packageManager: yarn@4.x" projects when Yarn 1.x is shadowing Corepack (macOS/Homebrew)

Fixing "packageManager: yarn@4.x" projects when Yarn 1.x is shadowing Corepack (macOS/Homebrew)

This is the "Yarn 4 project, but my shell keeps running Yarn 1.22" problem.

You'll see an error like:

This project's package.json defines "packageManager": "yarn@4.9.4". However the current global version of Yarn is 1.22.22. ...the project is meant to be used with Corepack...

What happened

  • The project explicitly requires Yarn 4.9.4 via packageManager in package.json.
  • Node 22 includes Corepack, which can provide the correct Yarn version.
  • But my machine still ran Yarn 1.22.22 because a global Yarn binary was earlier in PATH and shadowed Corepack's Yarn shim.

Once I removed the global Yarn, yarn started resolving to Corepack-managed Yarn 4.9.4.


Symptoms

Running yarn dev:

  • complains that the project wants Yarn 4.9.4
  • says current Yarn is 1.22.22
  • recommends enabling Corepack

Even after:

corepack enable
corepack prepare yarn@4.9.4 --activate

...yarn -v still shows 1.22.22.

That means your yarn command is not Corepack's.


Quick fix (what worked)

1) Verify Node + Corepack exist

node -v
corepack --version

2) Enable Corepack + prepare the Yarn version

corepack enable
corepack prepare yarn@4.9.4 --activate

3) Confirm Yarn is being shadowed

which -a yarn
type -a yarn

Example output showed multiple yarn locations:

  • /opt/homebrew/opt/node@22/bin/yarn
  • /opt/homebrew/bin/yarn

If yarn -v still prints 1.22.22 at this point, you're hitting a global Yarn install (often npm).

4) Remove the shadowing Yarn

Homebrew uninstall may fail if Yarn isn't installed as a brew formula:

brew uninstall yarn
# Error: No such keg: /opt/homebrew/Cellar/yarn

If Yarn was installed via npm globally, remove it:

npm -g rm yarn

5) Refresh shell command cache, re-check Yarn version

hash -r
which yarn
yarn -v

At this point, yarn -v should print:

  • 4.9.4

If it does, you're good.


Install / run the project cleanly

Optional cleanup (helps when switching Yarn major versions):

rm -rf node_modules
rm -f yarn.lock

Then install + run:

yarn install
yarn dev

Useful fallback: bypass PATH entirely

If you don't want to fight PATH yet, you can test via Corepack directly:

corepack yarn -v
corepack yarn dev

If that works but yarn dev doesn't, the problem is definitely "wrong yarn binary in PATH."


Notes / gotchas

  • Yarn may print "A new stable version is available..." (e.g. 4.12.0). Ignore unless you want to upgrade the repo.
  • If which yarn points somewhere weird, you still have a shadowing install.
  • If yarn is in multiple places, which -a / type -a is the fastest way to see what's winning.

TL;DR command sequence

corepack enable
corepack prepare yarn@4.9.4 --activate

which -a yarn
type -a yarn

npm -g rm yarn   # if yarn is shadowing corepack

hash -r
yarn -v          # should be 4.9.4

yarn install
yarn dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment