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. Withyarn.lockthe log saysfound a yarn lockfile — installing exactly those versionsand runsyarn install. The build runs withCI=true, so Yarn 2 and later install immutably and YN0028 can appear in the build log. -
The Yarn version. If
package.jsonpins one withpackageManager, the build runs that version. Install failed shows the field. -
A second attempt. If the
yarn installthat Livops chose from the lockfile fails, the log saysyarn install did not work — trying npm install instead. npm does not readyarn.lock: it resolves versions frompackage.jsonitself, so a deploy that passes this way can run versions you never tested. Fixyarn.lockanyway. -
Your own install command. Set Settings → Install, or
installinlivops.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_failedand 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-versionanddevEnginesinpackage.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
- Yarn — Error codes (YN0028) (yarnpkg.com). Checked .
- Yarn — yarn install (yarnpkg.com). Checked .
- Yarn — Settings (.yarnrc.yml) (yarnpkg.com). Checked .
- Yarn 4.19.0 source — packages/yarnpkg-core/sources/Project.ts (raw.githubusercontent.com). Checked .
- Yarn 4.19.0 source — packages/plugin-essentials/sources/commands/install.ts (raw.githubusercontent.com). Checked .
- Yarn 1 (Classic) — yarn install (classic.yarnpkg.com). Checked .
- Yarn 1.22.22 source — src/reporters/lang/en.js (raw.githubusercontent.com). Checked .
- Yarn 1.22.22 source — src/cli/commands/install.js (raw.githubusercontent.com). Checked .
- Yarn — yarn set version (yarnpkg.com). Checked .
- Corepack — README (github.com). Checked .
Put your project online today
Connect GitHub or drop a folder. No card is asked for.
Deploy your Node appRelated
- ERR_PNPM_OUTDATED_LOCKFILE: Cannot install with frozen-lockfile because pnpm-lock.yaml is not up to date: how to fix itERR_PNPM_OUTDATED_LOCKFILE means pnpm was told to install exactly what pnpm-lock.yaml says (frozen-lockfile, the default in CI when a lockfile is present), and the lockfile no longer matches a package.json: a dependency was added or changed without re-running pnpm install, or the updated lockfile was never committed. Run pnpm install locally, commit pnpm-lock.yaml, and the install passes.
- npm ci can only install packages when your package.json and package-lock.json are in sync: how to fix itnpm ci can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync (npm error code EUSAGE) means the committed lockfile no longer matches package.json: a dependency was added or changed without re-running npm install, or the lockfile was not committed. Run npm install locally, commit package.json and package-lock.json together, and npm ci passes.
- npm ERR! code ERESOLVE unable to resolve dependency tree: how to fix itnpm ERR! code ERESOLVE, unable to resolve dependency tree (npm error ERESOLVE in newer npm) means two packages in your project need versions of a shared peer dependency that cannot both be met. Since npm 7 installs peer dependencies, it stops instead of guessing. The real fix is to make the versions match: upgrade the package that is behind, or use the version it supports. --legacy-peer-deps and --force only skip the check.
- npm failed with return code 1 (npm ERR! code 1): how to fix the buildnpm failed with return code 1, or npm install exited with 1, is npm ERR! code 1 in newer npm: it only says that a script npm ran exited with code 1. The real error is printed above it: usually a compile or type error, a lockfile out of sync with package.json, or a dependency whose install script failed. Find the first error line above code 1, fix that, and the build passes.
- Error: Cannot find module (MODULE_NOT_FOUND) in Node.js: how to fix itError: Cannot find module 'x' with code MODULE_NOT_FOUND, or ERR_MODULE_NOT_FOUND with import, means Node.js looked for a package or file and it was not there. On a server the usual causes are a package missing from package.json, a devDependency the install skipped, a path whose case differs from the file, a start command pointing at a file that was never built, or an ES module import without its .js extension.
- Node.js hosting in 2026: how to deploy an Express appA Node.js server in production needs one long-running process that listens on the port it is given, restarts when it crashes and exits cleanly on SIGTERM. On Livops you push a repository with package.json and it runs as a web app for 39 credits a month (39,000 so'm). Here is what Node needs, and how a VPS, Render, Railway, Fly.io, DigitalOcean and Heroku compare.
- Next.js hosting without Vercel: the options comparedNext.js runs on any host that runs Node: next build, then next start, and every feature works, Server Actions and image optimization included. On Livops a repository with next in package.json runs as a server from a push for 39 credits a month (39,000 so'm), and a static export is free. Here is how Vercel, Render, Railway, Fly.io and a VPS compare.