Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Yarn install fails in CI because the lockfile would change

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

Short answer

Yarn refuses to run when package.json asks for something yarn.lock does not record, and you told it not to touch the lockfile. Run a normal install on your machine, commit the new yarn.lock, and keep the CI flag. On Yarn 2 and later, CI turns the same check on by itself.

  • Applies to Yarn 1.22, Yarn 4, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Run the install the way your machine normally does it, then look at what changed in the lockfile. If yarn.lock shows a diff, the committed file was out of date.

    yarn install
    git diff --stat yarn.lock
  2. 2Match what you see, then jump to its fix

    1. 1The CI job fails right after someone added, removed or bumped a dependencypackage.json was edited but yarn.lock was not committed with itFix
    2. 2The same install works on your laptop but fails on the CI runner, with no flag in your scriptYarn 2+ runs in immutable mode on CI by itselfFix

What does the error look like?

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

Cause 1 of 2

package.json was edited but yarn.lock was not committed with it

1Check

Yarn 1 installs the recorded versions when yarn.lock satisfies package.json, and rewrites yarn.lock when it does not. The frozen flag turns that rewrite into a failure.

yarn install
git status --short yarn.lock package.json

2Fix

Let a normal install update the lockfile on your machine, then commit it in the same change as package.json.

git add package.json yarn.lock
git commit -m "Update dependencies and lockfile"

3Verify

Run the strict install locally; it must finish without changing anything.

yarn install --frozen-lockfile

Confirmed by classic.yarnpkg.com

Did this fix it?

Cause 2 of 2

Yarn 2+ runs in immutable mode on CI by itself

1Check

In current Yarn, --immutable aborts with an error exit code if the lockfile would be modified, and its default is true on CI. The old --frozen-lockfile name is only a backward-compatible alias.

yarn --version
grep -n "install" .github/workflows/*.yml

2Fix

Update the lockfile locally with a plain install and commit it. Use --immutable in scripts instead of the alias.

yarn install
git add yarn.lock && git commit -m "Refresh yarn.lock"
# in CI
yarn install --immutable

3Verify

The strict command exits with code 0 and leaves yarn.lock untouched.

yarn install --immutable
echo $?

Confirmed by yarnpkg.com

Did this fix it?

How do I stop it coming back?

  • Commit package.json and yarn.lock together, always.
  • Keep the strict flag in CI; it is what catches a forgotten lockfile.
  • Use one Yarn major version on every machine and in CI, and record it in the repository.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

ng serve says it cannot determine the project or target

Cannot determine project for command.

The Angular CLI looked through angular.json for a project that defines the target you asked for (serve, build, test) and found none, or found several and could not pick one.

3 causes, each with a fix

Back end

ng serve cannot find the dev-server builder package

Could not find the implementation for builder @angular/build:dev-server

The builder named in angular.json (for example @angular-devkit/build-angular:dev-server) is looked up as an npm package starting from the workspace root.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.