Introducing Livops 2.0! Promo codeCEOgives you 8,000 so‘m on your balance.What’s new

YN0028: The lockfile would have been modified by this install, which is explicitly forbidden: how to fix it

YN0028 (FROZEN_LOCKFILE_EXCEPTION) means Yarn was running an immutable install, the default on CI, and finishing it would have changed yarn.lock: a dependency was added or changed without re-running yarn install, the updated yarn.lock was not committed, or another Yarn release needs to migrate the lockfile. Run yarn install locally with the project's Yarn version and commit yarn.lock. Yarn 1 says the same with: Your lockfile needs to be updated, but yarn was run with --frozen-lockfile.

By Livops team, the people who build and run LivopsUpdated

The error people search for, as Yarn 2 and later print it[4]:

YN0028: The lockfile would have been modified by this install, which is explicitly forbidden.

In the log the line carries Yarn’s usual prefix, and the lines just above it, under the same code, show the part of yarn.lock that would have changed[4]. Yarn 1 (Classic) stops on the same problem with another message[7][8]:

Your lockfile needs to be updated, but yarn was run with `--frozen-lockfile`.

This page explains what an immutable install checks, why it is on in CI without your asking, the causes and the fix for each, and how to pin one Yarn version for everybody. The npm and pnpm versions of the same problem have their own pages: npm ci: package.json and package-lock.json not in sync and ERR_PNPM_OUTDATED_LOCKFILE.

What does the error mean?

YN0028 is FROZEN_LOCKFILE_EXCEPTION[1]. With --immutable, Yarn makes sure the install does not modify the lockfile, and throws this error when it would, for example because a newly added package is missing from the lockfile, or because the current Yarn release needs to migrate the lockfile before it can work with it[1].

You may never have typed the flag. --immutable defaults to true on CI[2]. The setting behind it is enableImmutableInstalls in .yarnrc.yml: when true, the default on CI, Yarn refuses to change the lockfile in any way, whether it would add entries or remove them[3]. That is why the same commit installs on your machine and fails on the build server.

The Yarn 1 message comes from --frozen-lockfile, which in Yarn 1 means: don’t generate a yarn.lock and fail if an update is needed[6]. Yarn 1 throws it when that flag is set and the lockfile is not clean or is missing a dependency pattern[8]. In Yarn 2 and later, --frozen-lockfile is kept only as a deprecated alias of --immutable[2][5].

Causes, most common first

1. package.json changed, yarn.lock did not

You edited a version by hand, resolved a merge conflict in package.json only, or a bot bumped a range and left the lockfile behind. Fix — Yarn’s own: run yarn install in your development environment and commit the updated lockfile[1]:

yarn install
git add package.json yarn.lock
git commit -m "Update yarn.lock"

To update only the lockfile, without linking node_modules, yarn install --mode=update-lockfile fetches only the packages missing from the lockfile and skips the link step[2].

2. yarn.lock was never committed

You did run yarn install, but only package.json went into the commit: git status shows yarn.lock as modified. If the repository has no yarn.lock at all, an immutable install stops with a sibling message under the same code[4]:

YN0028: The lockfile would have been created by this install, which is explicitly forbidden.

Take yarn.lock out of .gitignore and commit it:

git add -f yarn.lock
git commit -m "Commit yarn.lock"

3. Another Yarn release installs it

Yarn’s own documentation names this case: the current Yarn release needs some kind of migration before it can work with the lockfile[1]. A lockfile written by one Yarn version and installed by another can fail even when package.json did not change. Compare yarn --version on your machine with the version in the build log, then pin one version (next section) and regenerate the lockfile with it.

4. CI passes –frozen-lockfile to Yarn 1

A CI script written for Yarn 1 often runs yarn install --frozen-lockfile, as Yarn 1’s documentation advises for reproducible installs[6]. The fix is the same as cause 1: run yarn install locally with the same Yarn 1 version and commit yarn.lock.

Pin the Yarn version: packageManager and Corepack

yarn set version sets the packageManager field at the root of your project[9]:

yarn set version stable     # the latest Yarn 2+ release
yarn set version classic    # the latest Yarn 1 release

The field in package.json looks like this (a hash after the version is optional but recommended)[10]:

{
  "packageManager": "[email protected]"
}

Corepack reads it and runs exactly that Yarn[10]. Corepack is distributed with Node.js from 14.19.0 up to, but not including, 25.0.0[10]: on those versions run corepack enable; on Node 25 and later install it first with npm install -g corepack[10].

Turning the check off: the last resort

enableImmutableInstalls: false in .yarnrc.yml lets Yarn change the lockfile again, on CI too[3]. Most settings can also be given as environment variables, prefixed with YARN_ and written in snake case[3], so one build can run with:

YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn install

It makes YN0028 go away, and it is the wrong lasting fix: the server resolves the changed dependencies itself, so the build can get versions nobody tested, and the repository keeps the stale yarn.lock. Use it to unblock one build if you must, then fix and commit the lockfile.

How to confirm the fix locally

Run the same strict install CI runs, from a clean tree:

git status                 # yarn.lock must not show as modified
yarn install --immutable   # Yarn 2+; for Yarn 1: yarn install --frozen-lockfile

If it passes here with the same Yarn version, it passes on the server.

On Livops

What follows is how Livops builds a project today.

  • Which install runs. Livops picks the command from the lockfile you committed, in this order: pnpm-lock.yaml, yarn.lock, bun.lock, package-lock.json. With yarn.lock the log says found a yarn lockfile — installing exactly those versions and runs yarn install. The build runs with CI=true, so Yarn 2 and later install immutably and YN0028 can appear in the build log.

  • The Yarn version. If package.json pins one with packageManager, the build runs that version. Install failed shows the field.

  • A second attempt. If the yarn install that Livops chose from the lockfile fails, the log says yarn install did not work — trying npm install instead. npm does not read yarn.lock: it resolves versions from package.json itself, so a deploy that passes this way can run versions you never tested. Fix yarn.lock anyway.

  • Your own install command. Set Settings → Install, or install in livops.json, and that command runs as typed, with no second attempt. To have a stale lockfile always stop the deploy:

    {
      "install": "yarn install --immutable"
    }
  • When it still fails, the deploy stops as install_failed and the old version keeps running. Next to the failed build, the assistant’s button reads the log and explains what happened. See Install failed.

  • Node version. Livops builds with Node 22 and 24, and reads .nvmrc, .node-version and devEngines in package.json.

Questions

What does YN0028 mean?

YN0028 is FROZEN_LOCKFILE_EXCEPTION. Yarn was running an immutable install, and finishing it would have changed yarn.lock, so Yarn stopped instead. The lines Yarn prints above the message show what would have changed.

Why does it fail on CI but not on my machine?

Yarn turns on immutable installs by default on CI. On your machine yarn install simply updates yarn.lock. If that update was never committed, CI still has the old lockfile.

Is --frozen-lockfile the same as --immutable?

In Yarn 2 and later, --frozen-lockfile is a deprecated alias for --immutable. In Yarn 1 it is the real flag: it fails the install if yarn.lock needs an update, and the message is Your lockfile needs to be updated, but yarn was run with --frozen-lockfile.

Can I turn the check off?

Yes: enableImmutableInstalls false in .yarnrc.yml, or the same setting as the environment variable YARN_ENABLE_IMMUTABLE_INSTALLS. The install then passes, but the server resolves dependencies itself and the lockfile in the repository stays wrong. Fix yarn.lock instead and keep the check.

Should I delete yarn.lock and start over?

Only as a last resort. Without a lockfile every dependency can move to the newest version its range allows. Running yarn install with the lockfile in place changes only what package.json now asks for.

How do I make CI use the same Yarn version as me?

Run yarn set version with the version you want. It writes the packageManager field in package.json, and Corepack then runs exactly that Yarn wherever the project is installed.

Sources

  1. Yarn — Error codes (YN0028) (yarnpkg.com). Checked .
  2. Yarn — yarn install (yarnpkg.com). Checked .
  3. Yarn — Settings (.yarnrc.yml) (yarnpkg.com). Checked .
  4. Yarn 4.19.0 source — packages/yarnpkg-core/sources/Project.ts (raw.githubusercontent.com). Checked .
  5. Yarn 4.19.0 source — packages/plugin-essentials/sources/commands/install.ts (raw.githubusercontent.com). Checked .
  6. Yarn 1 (Classic) — yarn install (classic.yarnpkg.com). Checked .
  7. Yarn 1.22.22 source — src/reporters/lang/en.js (raw.githubusercontent.com). Checked .
  8. Yarn 1.22.22 source — src/cli/commands/install.js (raw.githubusercontent.com). Checked .
  9. Yarn — yarn set version (yarnpkg.com). Checked .
  10. Corepack — README (github.com). Checked .

Put your project online today

Connect GitHub or drop a folder. No card is asked for.

Deploy your Node app

Got a question? — @livops_uz