Skip to main content
Workspaces allow you to manage multiple packages within a single repository (monorepo).

Configuration

Define workspaces in the root package.json:
This tells Bun that every directory in packages/ is a workspace.

Glob patterns

Use glob patterns to match workspace directories:

Negative patterns

Exclude specific directories:

Structure

Typical monorepo structure:

Installing

Install all workspaces

From the root:
Installs dependencies for all workspace packages and links inter-workspace dependencies.

Install in specific workspace

Or from root:

Inter-workspace dependencies

Reference by name

Workspace packages can depend on each other:
The workspace: protocol tells Bun to link to the local workspace package.

Version protocols

Automatic linking

When you run bun install, workspace dependencies are automatically linked:

Adding dependencies

Add to specific workspace

From workspace directory:
From root:

Add workspace dependency

Or edit package.json manually:
Then run bun install.

Add to root workspace

Add shared development dependencies to root:
Root package.json:

Running scripts

Run in specific workspace

Or from root:

Run in all workspaces

Run a script across all workspaces:

Filtering workspaces

Run commands in specific workspaces:
With patterns:

Workspace resolution

Bun resolves workspace dependencies in this order:
  1. Exact workspace match
  2. Version range match within workspaces
  3. External registry

Resolution examples

Given workspaces:
  • @myorg/utils version 1.0.0
  • @myorg/helpers version 2.0.0

Publishing workspaces

Publish individual workspace

Workspace protocol in published packages

When publishing, workspace: dependencies are converted: Before publishing:
Published version:

Pre-publish validation

Ensure workspace dependencies exist in registry before publishing:

Common patterns

Shared TypeScript config

Root tsconfig.json:
Workspace tsconfig.json:

Shared development tools

Install shared tools at root:

Private packages

Mark workspace packages as private if not publishing:

Benefits

Code sharing

Share code between packages without publishing:

Dependency deduplication

Shared dependencies are hoisted to root node_modules:

Atomic changes

Make changes across multiple packages in a single commit:

Troubleshooting

Workspace not found

If Bun can’t find a workspace:
  1. Check workspace glob patterns in root package.json
  2. Ensure workspace has a package.json with name field
  3. Run bun install from root

Dependencies not linking

If workspace dependencies aren’t linking:

Version mismatches

Ensure workspace versions match dependency ranges:

Migration from other package managers

From npm/Yarn workspaces

Bun workspaces are compatible:
Replace workspace: protocols:

From pnpm

Convert pnpm-workspace.yaml:
To package.json:

Examples

Full stack monorepo

Structure:

Library monorepo

Structure: