Catalogs in Bun let you share common dependency versions across multiple packages in a monorepo. Rather than specifying the same versions repeatedly in each workspace package, you define them once in the root package.json and reference them consistently throughout your project.Documentation Index
Fetch the complete documentation index at: https://bun.com/docs/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Unlike traditional dependency management where each workspace package needs to independently specify versions, catalogs let you:- Define version catalogs in the root package.json
- Reference these versions with the
catalog:protocol - Update all packages simultaneously by changing the version in one place
How to Use Catalogs
Directory Structure Example
Consider a monorepo with the following structure:1. Define Catalogs in Root package.json
In your root-levelpackage.json, add a catalog or catalogs field within the workspaces object:
package.json
catalog or catalogs at the top level of the package.json file, that will work too.
2. Reference Catalog Versions in Workspace Packages
In your workspace packages, use thecatalog: protocol to reference versions:
packages/app/package.json
packages/ui/package.json
3. Run Bun Install
Runbun install to install all dependencies according to the catalog versions.
Catalog vs Catalogs
Bun supports two ways to define catalogs:-
catalog(singular): A single default catalog for commonly used dependenciesReference withpackage.jsoncatalog::packages/app/package.json -
catalogs(plural): Multiple named catalogs for grouping dependenciesReference withpackage.jsoncatalog:<name>:packages/app/package.json
Benefits of Using Catalogs
- Consistency: Ensures all packages use the same version of critical dependencies
- Maintenance: Update a dependency version in one place instead of across multiple package.json files
- Clarity: Makes it obvious which dependencies are standardized across your monorepo
- Simplicity: No need for complex version resolution strategies or external tools
Real-World Example
Here’s a more comprehensive example for a React application: Root package.jsonpackage.json
packages/app/package.json
packages/ui/package.json
packages/utils/package.json
Updating Versions
To update versions across all packages, change the version in the root package.json:package.json
bun install to update all packages.
Lockfile Integration
Bun’s lockfile tracks catalog versions, ensuring consistent installations across different environments. The lockfile includes:- The catalog definitions from your package.json
- The resolution of each cataloged dependency
bun.lock(excerpt)
Limitations and Edge Cases
- Catalog references must match a dependency defined in either
catalogor one of the namedcatalogs - Empty strings and whitespace in catalog names are ignored (treated as default catalog)
- Invalid dependency versions in catalogs will fail to resolve during
bun install - Catalogs are only available within workspaces; they cannot be used outside the monorepo
Publishing
When you runbun publish or bun pm pack, Bun automatically replaces
catalog: references in your package.json with the resolved version numbers.
The published package includes regular semver strings and no longer depends on
your catalog definitions.