/flags/yarn/yarn-install-frozen-lockfile
yarn install --frozen-lockfile (Yarn 1) and --immutable (Yarn 2+)
verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash)updated
- tool
- Yarn
- command
- yarn install
- flag
- --frozen-lockfile (Yarn 1), --immutable (Yarn 2+)
- default
- off locally; Yarn 2+ enables --immutable on CI
yarn install --frozen-lockfile installs dependencies from yarn.lock and fails if the lockfile would have to change, instead of silently updating it. Use it in CI so builds use exactly the versions you committed. It is a Yarn 1 (Classic) flag; Yarn 2 and later replace it with --immutable, which is turned on automatically when Yarn detects a CI environment.
The error when yarn.lock is out of date
A dependency is in package.json but not in yarn.lock (here the lockfile is empty):
cat > package.json <<'EOF'
{ "name": "app", "version": "1.0.0", "license": "MIT", "dependencies": { "is-number": "7.0.0" } }
EOF
touch yarn.lock
npx --yes yarn@1 install --frozen-lockfile --non-interactiveOutput · exit 1
yarn install v1.22.22 [1/4] Resolving packages... error Your lockfile needs to be updated, but yarn was run with `--frozen-lockfile`. info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
The same situation with Yarn 4 and --immutable (Yarn 4 runs here from its npm distribution, @yarnpkg/cli-dist):
cat > package.json <<'EOF'
{ "name": "app", "version": "1.0.0", "license": "MIT", "dependencies": { "is-number": "7.0.0" } }
EOF
touch yarn.lock
npx --yes @yarnpkg/cli-dist@4 install --immutable > install.log 2>&1
status=$?
grep -o 'YN0028: The lockfile.*' install.log
exit $statusOutput · exit 1
(no output)
Fix
Update the lockfile on a development machine and commit it:
yarn install # rewrites yarn.lock
git add yarn.lock package.json
git commit -m "Update yarn.lock"Then CI can keep --frozen-lockfile.
Yarn 1 vs Yarn 2+
| Yarn 1 (Classic) | Yarn 2, 3, 4 (Berry) | |
|---|---|---|
| Flag | --frozen-lockfile | --immutable |
| Default on CI | Off: you must pass the flag | On when a CI environment is detected |
| Error | error Your lockfile needs to be updated, but yarn was run with `--frozen-lockfile`. | YN0028: The lockfile would have been modified by this install, which is explicitly forbidden. |
| Config file setting | none (pass the flag) | enableImmutableInstalls in .yarnrc.yml |
Sources
Related pages
errors · pnpmERR_PNPM_NO_LOCKFILE Cannot install with "frozen-lockfile" because pnpm-lock.yaml is absentpnpm install fails with ERR_PNPM_NO_LOCKFILE in CI because frozen-lockfile is on and pnpm-lock.yaml is not committed. Commit the lockfile from a local install.compare · npmnpm ci vs npm install: differences and when to use eachnpm ci installs exactly what package-lock.json says, deletes node_modules first and never edits the lockfile; npm install resolves ranges and may update it.cheat sheets · npmnpm cheat sheet: install, run, update, publishnpm cheat sheet: init, install and uninstall, version specifiers, scripts, outdated and update, npm ci for CI, ls and explain, config and cache commands.codes · yarnYarn error codes YN0000 – YN0092: what YN0028, YN0002, YN0060 and the others meanYarn 2+ tags every message with a YN code: YN0028 frozen lockfile, YN0002 missing peer dependency, YN0060 incompatible peer, YN0009 build failed. Code table.