Compatibility
bun install is an npm client that writes a Node.js compatible node_modules folder. The Bun team says it can replace npm install in a Node.js project without code changes and without using Bun’s runtime.
- It converts
package-lock.jsonto Bun’sbun.lockformat automatically, keeping the dependency versions you have already resolved. - It reads registry configuration from npm’s
.npmrc, so both clients can share one configuration. - It supports the
"workspaces"array inpackage.json.
Before you switch
- Install. Run
bun install(orbun i) where you rannpm install. That single command performs the migration. - Map the everyday commands.
bun i -d <package>adds a devDependency,bun rm <package>removes one, andbun outdatedworks likenpm outdated. - Map the run commands.
npm run <script>becomesbun <script>,npm exec <bin>becomesbun <bin>,node <file>becomesbun <file>, andnpx <package>becomesbunx <package>. - Replace workspace flags.
npm run --workspace lib-foo --workspace lib-bar my-scriptbecomesbun --filter 'lib-*' my-script.
The guide only mentions package-lock.json. It says nothing about npm-shrinkwrap.json, about keeping or deleting the npm lockfile, or about CI.
Pitfalls
- A
#!/usr/bin/env nodeshebang still runs Node.bun runrespects it and uses the system’snodeexecutable. Pass--bun(bun --bun my-scriptorbun run --bun my-script) to run the script on Bun’s runtime instead. bun --filterruns the command concurrently in every workspace package whosenamematches the glob, in dependency order.bun update <package>stays within the semver range inpackage.json. Add--latestto ignore it.- Global packages installed with
bun i -ggo to.bun/install/global/node_modulesin your home directory by default. - On Windows and Linux,
bun installuses hardlinks.