Skip to content
Latchkey

yarn "error Command failed with exit code 1" - Diagnose the Real Failure in CI

"Command failed with exit code 1" is yarn reporting that a script it ran exited non-zero. Like npm’s ELIFECYCLE, it is a wrapper - the real failure is in the lines above it.

What this error means

A yarn <script> step ends with error Command failed with exit code 1. The actual error - a failed test, a compiler error, a missing file - is printed just before the yarn summary, not in it.

yarn output
$ tsc -p tsconfig.json
src/index.ts:12:7 - error TS2322: Type 'string' is not assignable to type 'number'.

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation.

Common causes

The underlying command failed

The exit-code-1 message just reflects that the command your script ran returned non-zero - a failed build, test, or lint. yarn is the messenger.

How to fix it

Read above the yarn summary

  1. Scroll up from error Command failed with exit code 1 to the real error.
  2. Reproduce the underlying command directly (e.g. run tsc -p tsconfig.json) to iterate faster.
  3. Fix that error; the yarn wrapper message goes away with it.

How to prevent it

  • Treat the message as "my script failed", not a yarn bug.
  • Surface the real command’s output clearly in CI logs.

Related guides

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