Skip to content
Latchkey

Yarn Berry cache not persisted (slow install) in CI

Yarn Berry stores package archives in .yarn/cache. If that directory is neither committed (zero-installs) nor cached across CI runs, every job re-downloads all archives, making installs slow and registry-dependent.

What this error means

yarn install shows a full "Fetch step" downloading every package on each run, and job times stay high even when dependencies did not change.

yarn
YN0000: - Fetch step
YN0013: - 812 packages were added to the project (+ 214 MB).
YN0000: - Completed in 1m 48s

Common causes

The .yarn/cache is not persisted

Without a committed cache or a CI cache keyed on yarn.lock, the fetch step starts empty and re-downloads everything.

Global folder used but not cached

With enableGlobalCache, archives live in a global folder that CI also fails to persist, so they are re-fetched.

How to fix it

Cache .yarn/cache keyed on yarn.lock

Persist the local cache across runs so the fetch step reuses archives.

.github/workflows/ci.yml
- uses: actions/cache@v4
  with:
    path: .yarn/cache
    key: yarn-cache-${{ hashFiles('yarn.lock') }}

Or use zero-installs and commit the cache

  1. Set enableGlobalCache: false so archives live in .yarn/cache.
  2. Commit .yarn/cache so CI needs no fetch at all.
  3. Run yarn install --immutable in CI.
.yarnrc.yml
enableGlobalCache: false

How to prevent it

  • Cache .yarn/cache keyed on the lockfile, or commit it for zero-installs.
  • Set enableGlobalCache: false when caching a project-local cache.
  • Confirm the fetch step reuses rather than re-adds packages.

Related guides

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