Configuration
Define workspaces in the rootpackage.json:
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:Install in specific workspace
Inter-workspace dependencies
Reference by name
Workspace packages can depend on each other:workspace: protocol tells Bun to link to the local workspace package.
Version protocols
Automatic linking
When you runbun install, workspace dependencies are automatically linked:
Adding dependencies
Add to specific workspace
From workspace directory:Add workspace dependency
package.json manually:
bun install.
Add to root workspace
Add shared development dependencies to root:Running scripts
Run in specific workspace
Run in all workspaces
Run a script across all workspaces:Filtering workspaces
Run commands in specific workspaces:Workspace resolution
Bun resolves workspace dependencies in this order:- Exact workspace match
- Version range match within workspaces
- External registry
Resolution examples
Given workspaces:@myorg/utilsversion1.0.0@myorg/helpersversion2.0.0
Publishing workspaces
Publish individual workspace
Workspace protocol in published packages
When publishing,workspace: dependencies are converted:
Before publishing:
Pre-publish validation
Ensure workspace dependencies exist in registry before publishing:Common patterns
Shared TypeScript config
Roottsconfig.json:
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 rootnode_modules:
Atomic changes
Make changes across multiple packages in a single commit:Troubleshooting
Workspace not found
If Bun can’t find a workspace:- Check workspace glob patterns in root
package.json - Ensure workspace has a
package.jsonwithnamefield - Run
bun installfrom 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:workspace: protocols:
From pnpm
Convertpnpm-workspace.yaml:
package.json: