Skip to content
Latchkey

Yarn "Usage Error" / wrong version from corepack in CI

When corepack is active, Yarn honors the exact version in packageManager. A mismatch, or Yarn not being provisioned at all, surfaces as a "Usage Error" or "command not found" before install even starts.

What this error means

A yarn step fails with "Usage Error: This project is configured to use yarn" or "yarn: command not found", because corepack was not enabled or the pinned version was not prepared.

yarn
Usage Error: This project is configured to use yarn because /home/runner/work/app/app/package.json has a "packageManager" field

$ yarn ...

Common causes

Corepack is not enabled

The packageManager field pins Yarn, but corepack was never enabled, so the pinned Yarn is not provisioned.

A global Yarn conflicts with the pinned version

A classic Yarn on PATH does not match the packageManager version corepack expects, so corepack refuses.

How to fix it

Enable corepack and prepare the version

  1. Set packageManager to the exact Yarn version.
  2. Enable corepack and prepare/activate that version.
  3. Confirm with yarn --version.
.github/workflows/ci.yml
- run: corepack enable
- run: corepack prepare yarn@4.5.0 --activate
- run: yarn install --immutable

Pin the version in package.json

Let the field drive corepack so local and CI always agree on the Yarn version.

package.json
{
  "packageManager": "yarn@4.5.0"
}

How to prevent it

  • Enable corepack before any yarn step in CI.
  • Pin one exact Yarn version in packageManager.
  • Avoid a conflicting global Yarn on the runner.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →