bun.lock can accumulate several versions of the same package even though one of them satisfies every range. For example, it can contain both esbuild@0.15.10 and esbuild@0.15.11 when the ranges are ^0.15.7 and ^0.15.8. bun dedupe collapses these onto the smallest set of already-locked versions (preferring newer ones), saves bun.lock, and installs.
terminal
bun dedupe only chooses between versions already in the lockfile and never modifies package.json. It never fetches new versions from the registry and never moves a dependency outside its range. Use bun update for that.
--check and --dry-run
--check reports what Bun would remove without changing anything, and exits 1 if there are duplicates. Use it in CI:
terminal
--dry-run prints the same output but always exits 0.
--lockfile-only rewrites bun.lock without installing.
Notes
- Bun respects overrides and catalogs. It re-points each dependency using its effective range.
- Bun may move a direct dependency to an older locked version if that’s the only way to remove a duplicate (e.g. a transitive dependency pins it exactly). Use
bun updateor an override if you want the newer one to win. - Bun never removes versions in
patchedDependencies. If that forces another version to be kept too, Bun prints akept …line explaining why. - Dependencies on a dist-tag, git URL, or tarball keep their resolved version.
- Requires a lockfile that matches
package.json. If dependencies changed since the last install, it exits withbun.lock does not match package.json. Runbun installfirst. Bun migrates apackage-lock.json,yarn.lock, orpnpm-lock.yamlautomatically. - Cannot be combined with
--frozen-lockfile,--production, or--no-save; use--checkinstead. - With the isolated linker, several copies of the same version that differ only in peer dependencies are not duplicates, and Bun does not report them.
bun prunecleans up stale store entries.