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.
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
- Set
packageManagerto the exact Yarn version. - Enable corepack and prepare/activate that version.
- Confirm with
yarn --version.
- run: corepack enable
- run: corepack prepare yarn@4.5.0 --activate
- run: yarn install --immutablePin the version in package.json
Let the field drive corepack so local and CI always agree on the Yarn version.
{
"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.