Yarn Berry "YN0028: The lockfile would have been modified" in CI
Yarn Berry runs with --immutable in CI (via enableImmutableInstalls). It resolved dependencies, found the result would change yarn.lock, and refused because immutable installs forbid lockfile edits.
What this error means
yarn install fails with "YN0028: The lockfile would have been modified by this install, which is explicitly forbidden" during an immutable install in CI.
yarn
> YN0028: The lockfile would have been modified by this install, which is explicitly forbidden.
Error: The lockfile would have been modified by this install, which is explicitly forbidden.Common causes
yarn.lock is out of date with package.json
A dependency changed but yarn.lock was not regenerated and committed, so an immutable install would need to rewrite it.
yarn.lock was not committed after a local install
The manifest change landed but the lockfile update was left uncommitted, so CI sees a stale lock.
How to fix it
Regenerate and commit yarn.lock
- Run
yarn installlocally (without--immutable) to update the lockfile. - Commit the updated
yarn.lockalongside the manifest change. - Push so CI's immutable install matches.
Terminal
yarn install
git add yarn.lock
git commit -m "chore: update yarn.lock"Keep --immutable in CI
Run installs immutably in CI so drift fails fast; do not switch to a mutable install to hide it.
.github/workflows/ci.yml
- run: yarn install --immutableHow to prevent it
- Commit
yarn.lockin the same commit as any dependency change. - Keep
enableImmutableInstallson in CI so drift is caught. - Resolve lock conflicts by re-running
yarn install, not hand-editing.
Related guides
Yarn Berry "YN0000: ... couldn't be located" cache miss in CIFix Yarn Berry "YN0000: ... Package ... couldn't be located and ... immutable" in CI - a package archive is m…
Yarn Berry cache not persisted (slow install) in CIFix slow Yarn Berry installs in CI - without committing or caching .yarn/cache every run re-downloads all pac…
pnpm "ERR_PNPM_OUTDATED_LOCKFILE" with frozen-lockfile in CIFix pnpm "ERR_PNPM_OUTDATED_LOCKFILE: Cannot install with frozen-lockfile because pnpm-lock.yaml is not up to…