Skip to content

/flags/bun/bun-run-bun

bun run --bun: run package scripts and CLIs with Bun instead of Node.js

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash)updated
tool
Bun
command
bun run
flag
--bun
default
off (scripts and binaries keep their node shebang)

bun run --bun <script> forces package scripts and executables from node_modules/.bin to run on the Bun runtime. Without the flag, bun run is only a fast script runner: a script that calls node, or a CLI whose file starts with #!/usr/bin/env node (vite, next, eslint, tsc…), still runs on Node.js if it is installed. With --bun, Bun puts a temporary node on PATH that points to itself, so those commands run in Bun.

Same script, two runtimes

typeof Bun is "object" inside Bun and "undefined" in Node.js:

bash
cat > package.json <<'EOF'
{
  "name": "demo",
  "scripts": { "which": "node -p \"typeof Bun\"" }
}
EOF
echo "--- bun run which"
npx --yes bun@1 run which 2>/dev/null
echo "--- bun run --bun which"
npx --yes bun@1 run --bun which 2>/dev/null

Output

--- bun run which
undefined
--- bun run --bun which
object

The script text says node in both cases. Only the second run executes it in Bun, because --bun redirects the node command.

Where to put the flag

CommandRuntime for node-shebang tools
bun run devNode.js (shebang respected)
bun run --bun devBun
bun --bun run devBun (the flag may also come before run)
bunx viteNode.js when the binary has a node shebang
bunx --bun viteBun
[run] bun = true in bunfig.tomlBun for every bun run in the project
bun index.tsBun; the flag is not needed for files

The flag must come before the script name. In bun run dev --bun, the text --bun is passed to the script as an argument instead.

bunfig.toml

toml
[run]
# behave as if --bun were always passed
bun = true

This is handy for projects that are fully Bun-based, such as an Elysia or Hono server built with Vite: every bun run uses one runtime without repeating the flag.

When not to use it

  • Tools that rely on Node.js internals Bun does not implement yet may crash or behave differently. If a CLI fails only with --bun, run it without the flag.
  • Machines without Node.js: here bun run already falls back to Bun when no node binary exists, so the flag changes nothing.
  • Speed: Bun starts faster, but a long build is dominated by the tool's own work, so the gain is usually small.

A script that does not exist fails with Script not found. Running TypeScript files directly is covered in run a TypeScript file with Bun; type errors are not checked in either case.

FAQ

Why does bun run vite still use Node.js?

Package executables such as vite, next or tsc start with a #!/usr/bin/env node shebang, and bun run respects it, so Node.js runs them. Add --bun (bun run --bun vite, bunx --bun vite) to make Bun execute them.

Can I make --bun the default for a project?

Yes. Set bun = true under [run] in bunfig.toml; bun run then behaves as if --bun were passed. Remove it again if a tool only works on Node.js.

Does --bun affect files I run directly, like bun index.ts?

No. bun index.ts already runs the file with Bun. The flag only matters for package.json scripts and executables in node_modules/.bin that would otherwise start Node.js.

Sources