Yarn Berry "Cache path does not exist" / Hardened Mode - Fix in CI
Yarn Berry CI installs run with --immutable, which forbids changes to the lockfile and (with a committed offline cache) expects every package to already be present. A drifted lockfile or an incomplete cache fails the install.
What this error means
yarn install --immutable fails because the lockfile would change, or because a cache entry it expected is missing. It is deterministic - the committed state simply does not satisfy the immutable contract.
➤ YN0028: The lockfile would have been modified by this install,
which is explicitly forbidden.
➤ YN0000: Failed with errors in ...s
# or, with zero-installs cache committed:
Error: cache path does not exist for some-pkg@npm:1.2.3Common causes
The lockfile is out of sync under --immutable
A dependency change that was not committed to yarn.lock means the immutable install would have to modify it, which YN0028 forbids.
An incomplete committed offline cache (zero-installs)
With zero-installs, the .yarn/cache is committed. If a package’s cache artifact is missing, the immutable install cannot fetch it and fails.
How to fix it
Regenerate and commit lockfile (and cache)
Run a normal install locally to update yarn.lock (and the committed cache for zero-installs), then commit.
yarn install
git add yarn.lock .yarn/cache
git commit -m "chore: sync yarn lockfile and cache"Confirm the cache strategy
- For zero-installs, ensure
.yarn/cacheis fully committed (not gitignored). - For non-zero-installs, cache
.yarn/cachein CI keyed on yarn.lock instead of committing it. - Run
yarn installafter any dependency change so the lockfile and cache stay consistent.
How to prevent it
- Commit yarn.lock with every dependency change.
- Keep CI on --immutable and fix drift in the repo.
- Match the cache approach (zero-installs vs CI cache) consistently.