Isolated installs
Strict dependency isolation similar to pnpm's approach
With isolated installs, each package can only import the dependencies it declares, as with pnpm. This prevents phantom dependencies: imports that only work because some other package happened to install what they need.
Isolated installs are the default for new workspace/monorepo projects (with configVersion = 1 in the lockfile). Existing projects continue using hoisted installs unless explicitly configured.
What are isolated installs?#
The traditional "hoisted" strategy of npm and Yarn flattens dependencies into one shared node_modules folder, so any package can import anything that ends up there. Isolated installs give each package a folder that holds only its own dependencies.
Key benefits#
- No phantom dependencies: a package can't import a dependency it hasn't declared
- The same tree everywhere: what a package can import doesn't depend on what else is installed
- Better for monorepos: one workspace's dependencies don't leak into another
Using isolated installs#
Command line#
Use the --linker flag to specify the installation strategy:
# Use isolated installs
bun install --linker isolated
# Use traditional hoisted installs
bun install --linker hoistedConfiguration file#
Set the default linker strategy in your bunfig.toml or globally in $HOME/.bunfig.toml:
[install]
linker = "isolated"Default behavior#
The default linker strategy depends on your project's lockfile configVersion:
configVersion | Using workspaces? | Default Linker |
|---|---|---|
1 | ✅ | isolated |
1 | ❌ | hoisted |
0 | ✅ | hoisted |
0 | ❌ | hoisted |
New projects: Default to configVersion = 1. In workspaces, v1 uses the isolated linker by default; otherwise it uses hoisted linking.
Existing Bun projects (made pre-v1.3.2): If your existing lockfile doesn't have a version yet, Bun sets configVersion = 0 when you run bun install, preserving the previous hoisted linker default.
Migrations from other package managers:
- From pnpm:
configVersion = 1(using isolated installs in workspaces) - From npm or yarn:
configVersion = 0(using hoisted installs)
Override the default by passing the --linker flag or setting it in your configuration file.
How isolated installs work#
Directory structure#
Instead of hoisting dependencies, isolated installs create a two-tier structure:
node_modules/
├── .bun/ # Central package store
│ ├── node_modules/ # Hoisted fallback (see install.hoist)
│ │ └── package -> ../package@1.0.0/node_modules/package
│ ├── package@1.0.0/ # Versioned package installations
│ │ └── node_modules/
│ │ ├── .bin/ # Executables of the package and its dependencies
│ │ ├── package/ # Actual package files
│ │ └── dep -> ../../dep@2.0.0/node_modules/dep # One symlink per dependency
│ ├── @scope+package@2.1.0/ # Scoped packages (+ replaces /)
│ │ └── node_modules/
│ │ └── @scope/
│ │ └── package/
│ ├── package@1.0.0+f8a822eca018d0a1/ # The same version with other peer dependencies
│ └── ...
└── package-name -> .bun/package@1.0.0/node_modules/package # SymlinksEach store folder is named after the package and what it resolved to: a version for a registry package, or the path, URL or commit of a folder, tarball or git dependency.
In folder names, /, \, :, # and ? become +:
| Dependency | Store directory |
|---|---|
| npm registry | is-number@7.0.0, @types+react@18.2.0 |
folder (file: directory) | local-pkg@file+vendor+local-pkg |
| local tarball | bar@.+bar-0.0.2.tgz+3f2a9c01d47be650 |
| remote tarball | bar@https+++example.com+bar-0.0.2.tgz+3f2a9c01d47be650 |
| Git | pkg@git+https+++github.com+user+repo.git+<commit> |
| GitHub | pkg@github+user+repo+<commit> |
| with peer dependencies | react-dom@18.2.0+f8a822eca018d0a1 |
- A long path or URL is cut short and ends in a hash. Even so, a package's folder in the store can be over 100 characters deeper than your project. On Windows, a lifecycle script can't run in a folder whose path is longer than 260 characters, so keep such projects in a short path.
- Credentials and query strings in a URL are left out of the folder name.
- The root package, workspace packages and
link:dependencies have no store folder. Dependents link to where those packages are.
This describes the current layout. It can change between Bun versions.
Resolution algorithm#
- Central store — Bun installs all packages in
node_modules/.bun/package@version/directories - Symlinks — Top-level
node_modulescontains symlinks pointing to the central store - Peer resolution — Complex peer dependencies create specialized directory names
- Deduplication — Packages with identical package IDs and peer dependency sets are shared
- Re-linking — Later installs reuse a store entry that exists, without reading its files, and re-point its symlinks if a dependency changed. Run
bun install --forceto rebuild every entry, andbun pruneto delete the entries nothing uses
Workspace handling#
In monorepos, Bun handles workspace dependencies specially:
- Workspace packages — Symlinked directly to their source directories, not the store
- Workspace dependencies — Can access other workspace packages in the monorepo
- External dependencies — Installed in the isolated store
- Lifecycle scripts — A workspace package's scripts run after every dependency is installed, so they can use the root's dependencies and executables
Comparison with hoisted installs#
| Aspect | Hoisted (npm/Yarn) | Isolated (pnpm-like) |
|---|---|---|
| Dependency access | Packages can access any hoisted dependency | Packages only see declared dependencies |
| Phantom dependencies | ❌ Possible | ✅ Prevented |
| Disk usage | ✅ Lower (shared installs) | ✅ Similar (uses symlinks) |
| Determinism | ❌ Less deterministic | ✅ More deterministic |
| Node.js compatibility | ✅ Standard behavior | ✅ Compatible via symlinks |
| Best for | Single projects, legacy code | Monorepos, strict dependency management |
Advanced features#
Peer dependency handling#
Isolated installs encode peer dependencies in the store path:
# Package with peer dependencies creates specialized paths
node_modules/.bun/package@1.0.0+f8a822eca018d0a1/The directory name ends in a hash of the packages its peer dependencies resolved to, so each unique combination gets its own installation.
Strict resolution with install.hoist = false#
By default, Bun creates node_modules/.bun/node_modules, a fallback folder with a symlink for every dependency. It sits above every store entry, so a package in the store can still import a dependency it never declared. Set install.hoist = false (or hoist=false in .npmrc, as in pnpm) to leave it out, so undeclared imports fail. As in pnpm, the root node_modules is above the store too, so your direct dependencies, publicHoistPattern matches and workspace packages stay importable from any package:
[install]
linker = "isolated"
hoist = falseinstall.hoistPattern and install.publicHoistPattern offer pattern-based control over the same fallback directory and the root node_modules respectively.
Global virtual store#
When install.globalStore is enabled, Bun materializes store entries once into a global virtual store at <cache>/links/, and node_modules/.bun/<pkg>@<ver> is a symlink into it. Warm installs after rm -rf node_modules only create one symlink per package instead of copying every package's files again, which is roughly 7× faster on a typical mid-size project. The global store is off by default; see the global store docs for how to enable it, the full layout, benchmarks, and tradeoffs.
Backend strategies#
When the global store is disabled (the default) or an entry isn't eligible for it, Bun materializes the entry under the project using one of:
- Clonefile (macOS) — Copy-on-write filesystem clones
- Hardlink (Linux/Windows) — Hardlinks to save disk space
- Copyfile (fallback) — Full file copies when other methods aren't available
Debugging isolated installs#
Enable verbose logging to see what an install is doing:
bun install --linker isolated --verboseTroubleshooting#
Compatibility issues#
Some packages may not work correctly with isolated installs due to:
- Hardcoded paths — Packages that assume a flat
node_modulesstructure - Dynamic imports — Runtime imports that don't follow Node.js resolution
- Build tools — Tools that scan
node_modulesdirectly
If you encounter issues, you can:
Switch to hoisted mode for specific projects:
terminalbun install --linker hoistedSwitching linkers in either direction reinstalls
node_modulesfrom scratch. Bun keeps the folders of other tools, such as.cacheand.vite, and removes another package manager's, such as.pnpm. The old tree is deleted once the install succeeds. If it fails,bun pruneremoves what's left.If
node_modulesis a symlink, Bun clears nothing behind it and prints a warning. Empty the folder yourself before you switch.Report compatibility issues to help improve isolated install support
Migration guide#
From npm/Yarn#
rm -rf node_modules
bun install --linker isolatedBun converts package-lock.json or yarn.lock to bun.lock on this first install, so you keep the versions you had.
From pnpm#
Isolated installs are conceptually similar to pnpm, so migration is direct:
# Remove pnpm's node_modules
rm -rf node_modules
# Install with Bun's isolated linker
bun install --linker isolatedKeep pnpm-lock.yaml for this first install: Bun converts it to bun.lock, so you keep the versions pnpm resolved. It also moves the workspace list, catalogs and overrides from pnpm-workspace.yaml into the root package.json. See pnpm migration.
The layouts are close: Bun hardlinks (clones on macOS) packages from its global cache into a per-project store, node_modules/.bun/, and symlinks top-level node_modules entries into it. With install.globalStore enabled, those store entries become symlinks into a global virtual store instead.
When to use isolated installs#
Use isolated installs when:
- Working in monorepos with multiple packages
- Strict dependency management is required
- Preventing phantom dependencies is important
- Building libraries that need deterministic dependencies
Use hoisted installs when:
- Working with legacy code that assumes flat
node_modules - Compatibility with existing build tools is required
- Working in environments where symlinks aren't well supported
- You prefer the traditional npm behavior
Related documentation#
- Package manager > Workspaces — Monorepo workspace management
- Package manager > Lockfile — Understanding Bun's lockfile format
- CLI > install — Complete
bun installcommand reference