Yarn install fails in CI because the lockfile would change
error 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.
Fix it fast
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.lock2Match what you see, then jump to its fix
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.json2Fix
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-lockfileConfirmed by classic.yarnpkg.com
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/*.yml2Fix
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 --immutable3Verify
The strict command exits with code 0 and leaves yarn.lock untouched.
yarn install --immutable
echo $?Confirmed by yarnpkg.com
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 fixBack end
ng fails with Cannot find module @angular/cli/bin/ng
Cannot find module '@angular/cli/bin/ng'
The ng command is the entry point to the Angular CLI package.
2 causes, each with a fixBack end
Angular app shows 'Cannot GET /' when served by a Node.js server
Cannot GET /dashboard
Cannot GET / is Express saying no route or file matches the request.
3 causes, each with a fixBack 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 fixBack end
Angular build says it cannot resolve '@angular/localize/init'
Can't resolve '@angular/localize/init' in '/usr/src/app/src'
The build imports @angular/localize, and that package is not in node_modules.
2 causes, each with a fixBack end
The command npm run build -- --prod exited with code 1 (Angular)
The command "npm run build -- --prod" exited with code 1
Exit code 1 only says the build failed; the real message is above it.
2 causes, each with a fix