rembrembdocs

Skip to main content

Bun home pagelight logodark logo

[Runtime

](../../../index.md)[Package Manager

](../../../pm/cli/install/index.md)[Bundler

](../../../bundler/index.md)[Test Runner

](../../../test/index.md)[Guides

](../../index.md)[Reference

](https://bun.com/reference)[Blog

](https://bun.com/blog)[Feedback

](../../../feedback/index.md)

Bun’s package manager supports npm "workspaces". This allows you to split a codebase into multiple distinct “packages” that live in the same repository, can depend on each other, and (when possible) share a node_modules directory. Clone this sample project to experiment with workspaces.


The root package.json should not contain any "dependencies", "devDependencies", etc. Each individual package should be self-contained and declare its own dependencies. Similarly, it’s conventional to declare "private": true to avoid accidentally publishing the root package to npm.

package.json

{
  "name": "my-monorepo",
  "private": true,
  "workspaces": ["packages/*"]
}

It’s common to place all packages in a packages directory. The "workspaces" field in package.json supports glob patterns, so you can use packages/* to indicate that each subdirectory of packages should be considered separate package (also known as a workspace).

File Tree

.
├── package.json
├── node_modules
└── packages
    ├── stuff-a
    │   └── package.json
    └── stuff-b
        └── package.json

To add dependencies between workspaces, use the "workspace:*" syntax. Here we’re adding stuff-a as a dependency of stuff-b.

packages/stuff-b/package.json

{
  "name": "stuff-b",
  "dependencies": {
    "stuff-a": "workspace:*"
  }
}

Once added, run bun install from the project root to install dependencies for all workspaces.

terminal

bun install

To add npm dependencies to a particular workspace, cd to the appropriate directory and run bun add commands as you would normally. Bun will detect that you are in a workspace and hoist the dependency as needed.

terminal

cd packages/stuff-a
bun add zod

See Docs > Package manager for complete documentation of Bun’s package manager.

Was this page helpful?

Suggest editsRaise issue

[

Install a package under a different name

Previous

](../npm-alias/index.md)[

Override the default npm registry for bun install

Next

](../custom-registry/index.md)