Fixing “lockfile is frozen” Errors in Bun
bun install --frozen-lockfile and bun ci fail with "lockfile had changes, but lockfile is frozen" when the contents of package.json don't match the bun.lock you committed. To fix it, run bun install locally without any flags to update bun.lock, then commit it together with package.json.
This article covers the situation where, after you add a dependency, dependency installation starts failing in CI such as GitHub Actions. I deliberately triggered this error in a test environment for each cause, and I confirmed the messages it printed and that the error went away once I fixed the cause.
The test environment was Ubuntu 24.04, Bun 1.4.4, and Git 2.43.0. For the older Bun combination, I used Bun 1.2.0 installed through npm. Packages were fetched from registry.npmjs.org. I did not test Windows or macOS, real CI services (such as GitHub Actions), migration from bun.lockb or package-lock.json, or frozenLockfile in bunfig.toml.
- 1. Triggering the error by adding a dependency by hand
- 2. The note on the line after the error shows what changed
- 3. Running bun install locally and committing bun.lock
- 4. When "Unknown lockfile version" appears too, match the Bun version
- 5. Without the flag, or without bun.lock, this error does not appear
Triggering the error by adding a dependency by hand
I ran bun install in a project that only had ms, then committed the resulting bun.lock. Next, I added "is-number": "^7.0.0" to the dependencies in package.json by hand, left bun.lock unchanged, and ran bun install with --frozen-lockfile.
$ bun install --frozen-lockfile
bun install v1.4.4 (38afee6c8)
error: lockfile had changes, but lockfile is frozen
note: dependencies in package.json changed since bun.lock was saved: is-number was added
note: try re-running without --frozen-lockfile and commit the updated lockfile
The exit code was 1. According to git status --short, only package.json had changed, and bun.lock had not been rewritten.
bun ci and bun install --production printed exactly the same message. The official bun install documentation says bun ci is the same as bun install --frozen-lockfile, and --production also includes --frozen-lockfile. If you only pass --production when building a production image, you will also hit this error.
The note on the line after the error shows what changed
The note: line directly under error: shows how package.json differs from bun.lock. I changed package.json in different ways in the test environment, and got the following output.
| Change to package.json | note line |
|---|---|
| Added a dependency | is-number was added |
| Removed a dependency | is-number was removed |
Changed the ms range from ^2.1.3 to 2.1.2 |
ms changed from ^2.1.3 to 2.1.2 |
Added overrides |
overrides in package.json changed since bun.lock was saved |
Added a dependency to packages/web in workspaces |
is-number was added in packages/web |
According to the official bun install documentation on --frozen-lockfile, the error names only the first changed dependency. If you changed several things, look at the whole picture with git diff package.json.
Conversely, changes that keep the locked version do not cause an error. In the test environment, moving ms from dependencies to devDependencies finished installing without stopping. The same section also gives an example of changing ^1.0.0 to >=1.0.0, where the locked version still falls within the range.
Running bun install locally and committing bun.lock
If adding the dependency was intentional, run bun install locally without flags. This rewrites bun.lock.
$ bun install
bun install v1.4.4 (38afee6c8)
Saved lockfile
+ is-number@7.0.0
1 package installed [1.00ms]
Looking at the bun.lock diff, the range of the added dependency and its resolved version had been added.
$ git diff bun.lock
diff --git a/bun.lock b/bun.lock
index b621a53..aaa5538 100644
--- a/bun.lock
+++ b/bun.lock
@@ -5,11 +5,14 @@
"": {
"name": "app",
"dependencies": {
+ "is-number": "^7.0.0",
"ms": "^2.1.3",
},
},
},
"packages": {
+ "is-number": ["is-number@7.0.0", "", {}, "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng=="],
+
"ms": ["ms@2.1.3", "", {}, "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="],
}
}
In this state, running again with --frozen-lockfile made the error go away.
$ bun install --frozen-lockfile
bun install v1.4.4 (38afee6c8)
Checked 2 installs across 3 packages (no changes) [0.00ms]
Finally, stage both files with git add package.json bun.lock and include them in the same commit. CI reads the committed bun.lock, so fixing the file only on your machine will not clear the CI error.
The same fix works for projects that use workspaces. When I added a dependency to the package.json in packages/web, running bun install at the root updated bun.lock, and the following --frozen-lockfile run succeeded.
If the change was unintended, revert package.json. After I accidentally added is-odd and then ran git checkout -- package.json, --frozen-lockfile succeeded.
When adding dependencies, using bun add instead of editing package.json by hand makes mismatches less likely. I ran bun add is-odd, which updated both package.json and bun.lock, and the --frozen-lockfile run that followed also succeeded. If you want to check for a mismatch before pushing, without installing anything, you can use bun install --frozen-lockfile --dry-run, which the official documentation describes. In the test environment, a mismatch stopped with the same error, and the exit code was 1.
When "Unknown lockfile version" appears too, match the Bun version
If you also see error: Unknown lockfile version and warn: Ignoring lockfile above this error, the Bun in CI may be older than the Bun that wrote bun.lock. I read a bun.lock written by Bun 1.4.4 with bun install --frozen-lockfile from Bun 1.2.0, installed through npm, and it stopped as follows. I did not change package.json. (Bun 1.2.0 is installed at the example path /path/to/oldbun.)
$ /path/to/oldbun/node_modules/.bin/bun install --frozen-lockfile
bun install v1.2.0 (b0c5a765)
2 | "lockfileVersion": 2,
^
error: Unknown lockfile version
at bun.lock:2:22
UnknownLockfileVersion: failed to parse lockfile: 'bun.lock'
warn: Ignoring lockfile
error: lockfile had changes, but lockfile is frozen
The bun.lock written by Bun 1.4.4 starts with "lockfileVersion": 2, and Bun 1.2.0 cannot read that format. Because it ignored bun.lock and tried to regenerate it, it produced the "lockfile had changes, but lockfile is frozen" error. No note: line explaining a mismatch was printed. Reading the same bun.lock with Bun 1.4.4 installed without problems.
In this case, don't edit bun.lock. Instead, match the Bun version in CI to the version you used locally to write bun.lock. You can check your local version with bun --version. According to the README for oven-sh/setup-bun on GitHub Actions, you can specify the version with bun-version. If you don't, it checks packageManager in package.json (in the form "bun@1.0.25") and engines.bun. If neither is set, it installs the latest version.
Without the flag, or without bun.lock, this error does not appear
To catch a mismatch in CI, you need to explicitly use --frozen-lockfile, bun ci, or --production, and you need to commit bun.lock.
I ran plain bun install with the environment variable CI=true set. The dependency I had added to package.json was installed as-is, and bun.lock was rewritten (git status --short showed both bun.lock and package.json as modified). The official documentation also states that being in CI does not automatically enable --frozen-lockfile.
Also, when I ran bun install --frozen-lockfile in a folder without bun.lock, it did not produce an error. It installed the versions resolved from the ranges in package.json, and it did not create bun.lock.
$ ls -A
package.json
$ bun install --frozen-lockfile
bun install v1.4.4 (38afee6c8)
+ is-number@7.0.0
+ ms@2.1.3
2 packages installed [1.00ms]
$ ls -A
node_modules
package.json
In this case, the installed versions are whatever was resolved at the time you ran the command. If bun.lock is in .gitignore, the versions will not be pinned even if CI uses bun ci.





