skills/bun-pm-isolated-installs/SKILL.md
Strict dependency isolation similar to pnpm's approach
npx skillsauth add jarle/bun-skills Bun Isolated installsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Strict dependency isolation similar to pnpm's approach
Bun provides an alternative package installation strategy called isolated installs that creates strict dependency isolation similar to pnpm's approach. This mode prevents phantom dependencies and ensures reproducible, deterministic builds.
This is the default installation strategy for new workspace/monorepo projects (with configVersion = 1 in the lockfile). Existing projects continue using hoisted installs unless explicitly configured.
Isolated installs create a non-hoisted dependency structure where packages can only access their explicitly declared dependencies. This differs from the traditional "hoisted" installation strategy used by npm and Yarn, where dependencies are flattened into a shared node_modules directory.
Use the --linker flag to specify the installation strategy:
# Use isolated installs
bun install --linker isolated
# Use traditional hoisted installs
bun install --linker hoisted
Set the default linker strategy in your bunfig.toml or globally in $HOME/.bunfig.toml:
[install]
linker = "isolated"
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:
configVersion = 1 (using isolated installs in workspaces)configVersion = 0 (using hoisted installs)You can override the default behavior by explicitly specifying the --linker flag or setting it in your configuration file.
Instead of hoisting dependencies, isolated installs create a two-tier structure:
node_modules/
├── .bun/ # Central package store
│ ├── [email protected]/ # Versioned package installations
│ │ └── node_modules/
│ │ └── package/ # Actual package files
│ ├── @[email protected]/ # Scoped packages (+ replaces /)
│ │ └── node_modules/
│ │ └── @scope/
│ │ └── package/
│ └── ...
└── package-name -> .bun/[email protected]/node_modules/package # Symlinks
node_modules/.bun/package@version/ directoriesnode_modules contains symlinks pointing to the central storeIn monorepos, workspace dependencies are handled specially:
| 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 |
Isolated installs handle peer dependencies through sophisticated resolution:
# Package with peer dependencies creates specialized paths
node_modules/.bun/[email protected][email protected]/
The directory name encodes both the package version and its peer dependency versions, ensuring each unique combination gets its own installation.
Bun uses different file operation strategies for performance:
Enable verbose logging to understand the installation process:
bun install --linker isolated --verbose
This shows:
Some packages may not work correctly with isolated installs due to:
node_modules structurenode_modules directlyIf you encounter issues, you can:
Switch to hoisted mode for specific projects:
bun install --linker hoisted
Report compatibility issues to help improve isolated install support
# Remove existing node_modules and lockfiles
rm -rf node_modules package-lock.json yarn.lock
# Install with isolated linker
bun install --linker isolated
Isolated installs are conceptually similar to pnpm, so migration should be straightforward:
# Remove pnpm files
rm -rf node_modules pnpm-lock.yaml
# Install with Bun's isolated linker
bun install --linker isolated
The main difference is that Bun uses symlinks in node_modules while pnpm uses a global store with symlinks.
Use isolated installs when:
Use hoisted installs when:
node_modulesbun install command referencedevelopment
Using TypeScript with Bun, including type definitions and compiler options
development
Learn how to write tests using Bun's Jest-compatible API with support for async tests, timeouts, and various test modifiers
testing
Learn how to use snapshot testing in Bun to save and compare output between test runs
testing
Learn about Bun test's runtime integration, environment variables, timeouts, and error handling