website/docs/recipes/using-bun-with-lerna.md
Lerna can be used in a Bun workspace to get the full benefits of both Bun's native performance and Lerna's monorepo management capabilities.
When used with Bun, Lerna will:
bun runbun install --lockfile-only) during lerna version bumpspackage.json workspaces (same as npm/yarn)To set up Bun with Lerna:
If not installed already, install Bun: https://bun.sh/docs/installation
Remove the node_modules/ folder in the root, if it exists. Remove any existing lockfiles (package-lock.json, yarn.lock, or pnpm-lock.yaml).
Set "npmClient": "bun" in lerna.json.
Ensure package.json has a workspaces property configured:
{
"name": "my-monorepo",
"private": true,
"workspaces": ["packages/*"]
}
Run bun install to generate a bun.lock file.
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"version": "1.0.0",
"npmClient": "bun"
}
{
"name": "my-monorepo",
"private": true,
"workspaces": ["packages/*"],
"devDependencies": {
"lerna": "^9.0.0"
}
}
package.json workspaces - no additional configuration files neededBun v1.2+ uses a text-based bun.lock lockfile by default. Older versions of Bun use a binary bun.lockb format instead. Lerna supports both formats.
If you are still using the legacy binary bun.lockb format, keep in mind:
The text-based bun.lock format has none of these limitations, so consider migrating to it.
When you run lerna version, Lerna regenerates the root lockfile by running bun install --lockfile-only so that it picks up the bumped package versions. Because the lockfile is regenerated from scratch by your installed version of Bun, running lerna version with Bun v1.2+ on a repo that only has a legacy bun.lockb will migrate it to the text-based bun.lock format. Lerna stages both the removal and the regenerated lockfile in the version commit, so the migration is captured cleanly - but if you want to stay on the binary format, commit the migration consciously or update Bun's lockfile settings first.
When lerna init auto-detects the package manager, bun lockfiles (bun.lock/bun.lockb) take priority over other package managers' lockfiles. If your project has multiple lockfiles, remove the ones you don't need to avoid unexpected detection results.
Most Lerna commands work seamlessly with Bun:
lerna init - Auto-detects Bun and configures accordinglylerna run - Executes scripts using bun runlerna version - Regenerates the bun lockfile automaticallylerna publish - Full publishing workflow supportlerna changed - Detects changed packages correctlylerna exec - Runs commands across packagesNote: Lerna's legacy dependency management commands (bootstrap, add, and link) were removed in Lerna v7. Use bun install and bun add directly instead.
# 1. Install Bun
curl -fsSL https://bun.sh/install | bash
# 2. Update lerna.json
# Set "npmClient": "bun"
# 3. Remove old lockfile
rm package-lock.json # or yarn.lock
# 4. Install with Bun
bun install
# 5. Verify
bunx lerna list
# 1. Install Bun
curl -fsSL https://bun.sh/install | bash
# 2. Move workspace config from pnpm-workspace.yaml to package.json
# pnpm-workspace.yaml:
# packages:
# - "packages/*"
#
# becomes package.json:
# "workspaces": ["packages/*"]
# 3. Update lerna.json
# Set "npmClient": "bun"
# 4. Remove pnpm files
rm pnpm-lock.yaml pnpm-workspace.yaml
# 5. Install with Bun
bun install
# 6. Verify
bunx lerna list
If the bun lockfile isn't being updated during lerna version, ensure:
bun.lock or bun.lockb) exists in the root directory - if none exists, Lerna skips the lockfile update"npmClient": "bun" is set in lerna.jsonPATHBun's first install may download and cache packages. Subsequent installs will be significantly faster thanks to Bun's global cache.
If lifecycle scripts aren't executing, check:
package.json of the relevant packageslerna run <script> (not lerna exec bun run <script>)