.js, .ts, .jsx, and .tsx files natively, and is compatible with the npm ecosystem. Most projects work with Bun after a handful of command substitutions.
Step-by-step migration
Replace npm scripts with Bun equivalents
The most common command substitutions:
Update the
| Node.js / npm | Bun |
|---|---|
npm install | bun install |
npm install <pkg> | bun add <pkg> |
npm install -D <pkg> | bun add -d <pkg> |
npm uninstall <pkg> | bun remove <pkg> |
npm run <script> | bun run <script> or bun <script> |
node <file> | bun <file> |
npx <package> | bunx <package> |
scripts in your package.json to use Bun:package.json
Run bun install
Replace your existing lockfile with Bun’s:Bun automatically converts
package-lock.json or yarn.lock to bun.lock, preserving your existing resolved dependency versions.TypeScript support
Bun runs TypeScript natively — nots-node, tsx, or compilation step required. For type checking, install @types/bun:
tsconfig.json for Bun projects:
tsconfig.json
Node.js globals
The following Node.js globals work in Bun without changes:CommonJS and ESM
Bun supports both CommonJS (require) and ESM (import) in the same project. You do not need to add "type": "module" to package.json — Bun infers the module format from the file extension and package.json fields:
When mixing CJS and ESM in the same file, Bun follows the same rules as Node.js.
.mjs files are always ESM; .cjs files are always CommonJS.npm package compatibility
Virtually all packages from the npm registry work with Bun. Packages that rely on Node.js built-in modules (fs, path, crypto, http, etc.) are supported via Bun’s Node.js compatibility layer.
A small number of packages that use native Node.js add-ons (.node files compiled with node-gyp) may not work. Check the Bun Node.js compatibility page for a full list of supported APIs.
Common gotchas
Packages with #!/usr/bin/env node shebang
Packages with #!/usr/bin/env node shebang
By default, Bun respects the
node shebang and uses the system’s Node.js executable. To force Bun’s runtime, pass --bun:Dynamic require() in ESM files
Dynamic require() in ESM files
If you see
require is not defined errors, the file is being treated as ESM. Either rename the file to .cjs or convert to import syntax.Missing process.env values
Missing process.env values
Bun loads
.env files automatically. You do not need dotenv. If a variable is missing, ensure the .env file is in the project root or use Bun.env.node_modules resolution
node_modules resolution
Bun uses Node.js module resolution by default. If a package is not found, run
bun install to ensure all dependencies are present.