bun run: Run Scripts and Files
bun run executes a package.json script or a source file directly with Bun, no build or transpile step required.
bun run is the workhorse for CI steps: lint, build, test, deploy. It runs TypeScript and JSX natively, so there is usually nothing to compile first.
What it does
bun run <script> executes the named script from package.json. bun run <file> executes a .js/.ts/.tsx file directly with the Bun runtime. The --bun flag forces tools that would normally spawn Node to run under Bun instead.
Common usage
bun run build # package.json script
bun run ./scripts/migrate.ts # run a TS file directly
bun run --bun next build # force the script to use Bun, not Node
bun run --filter './packages/*' build # run build in every workspaceOptions
| Flag | What it does |
|---|---|
| --bun | Run the target with Bun even if its bin shebang says node |
| --filter <pattern> | Run the script across matching workspace packages |
| --watch | Re-run on file changes (dev, not CI) |
| --silent | Suppress Bun preamble output |
| --cwd <dir> | Run as if started from the given directory |
In CI
Use bun run <script> for build and lint steps so they pick up the package.json definition. In a monorepo, bun run --filter runs a script across workspaces in dependency order. Add --bun when a tool misbehaves under Node but works under Bun, but test it: not every Node tool is Bun-compatible yet.
Common errors in CI
"error: Script not found \"build\"" means the script name is missing from package.json or you are in the wrong directory; check with bun run with no args, which lists available scripts. "Cannot find module" at runtime means a dependency was not installed (run bun install first) or relies on a Node-only native module Bun does not yet implement.