bun-runtime
Guidance on using Bun as a JavaScript runtime, package manager, bundler, and test runner, including when to choose it over Node and how to migrate.
Pass rate with the skill minus without, same tasks, same model.
- Content Lift forced arm
- +25pp [0, +63]
- Trigger rate
- 100%
- Trials
- 23 · 7 tasks
- Model
- GLM-5.3-flash
- Measured
- 2026-10-15
Content Lift = the skill's instructions injected into the system prompt, so it measures what the content does once loaded, apart from whether the agent chooses to load it. Method →
Embed this score · live badge for your README
The badge shows the real benchmark number and updates itself when we re-bench — including the honest states (“did not trigger”, “not benched yet”). All badge options →
[](https://skillzbench.com/skills/bun-runtime)[](https://skillzbench.com/skills/bun-runtime)<a href="https://skillzbench.com/skills/bun-runtime"><img src="https://skillzbench.com/api/badge/bun-runtime.svg" alt="SkillzBench benchmark" height="20"></a>A/B outputs — median trial per arm
Chat harness (v2): the agent's final message without the skill (left) vs with it (right).
bun-runtime--m1
Recommendation: Stay with Node (with TypeScript), keep Bun as an experiment
For your specific constraints — npm packages, Windows developers, and Vercel deployment — Node.js is the safer choice today. Here's the practical reasoning:
Why Node wins for your case
1. Vercel deployment
- Vercel's serverless functions run on Node.js. Bun isn't a supported runtime for Vercel Functions.
- You can use Bun locally as a package manager/runner while deploying Node code, but then you're maintaining two toolchains — added complexity with no deploy-side payoff.
- Edge runtime and Node middleware on Vercel are mature; the Bun path would be nonstandard.
2. Windows support
- Bun's Windows support is significantly newer and less battle-tested than its macOS/Linux support. Some packages and Bun APIs have historically had Windows-specific gaps or performance differences.
- Your team is on Windows, so you'd be the ones hitting those rough edges first.
3. npm ecosystem compatibility
- Both handle npm packages, but Node has 15+ years of compatibility. Native modules, packages that poke at Node internals, or packages relying on subtle Node behaviors occasionally break under Bun. With a team project, "occasionally" is enough to matter.
4. Team familiarity
- Your team already knows Node's debugging, profiling, and operational quirks. That knowledge transfers directly to production incidents.
What you'd actually give up by skipping Bun
- Speed: Bun's startup and runtime speed is real, but for a typical REST API behind Vercel serverless functions, cold-start differences are modest and often dominated by your dependencies, not the runtime.
- Bundler/test runner: You don't need Bun for these. Good Node-native options:
- Tests: Vitest (fast, TS-native, great DX) or Node's built-in test runner
- Bundling: Usually unnecessary for a Vercel-deployed API; esbuild or tsup if you need it
- TypeScript:
tsxfor dev,tscfor build — no compile step friction
Suggested stack
- Runtime: Node 20+ (LTS)
- Framework: Express (or consider Fastify/Hono — Hono in particular is runtime-agnostic and runs great on Vercel)
- Package manager: pnpm (fast, strict, disk-efficient)
- Dev:
tsx watch, Tests: Vitest, Deploy: Vercel Node functions
When to revisit Bun
- If you later deploy to a Bun-friendly host (Fly.io, Railway, your own servers)
- If Bun's Windows support matures and you want a unified toolchain
- If you build a CLI or script-heavy tooling where Bun's startup speed genuinely pays off
Bottom line: Bun is a great tool, but it's not the right default for a Windows + Vercel + npm team project in production. Choose Node now, and adopt Bun opportunistically where it fits (e.g., as a faster local script runner) without betting your deployment on it.
Recommendation: Use Bun — with a Node escape hatch
For your specific constraints (new project, TypeScript, npm packages, Windows devs, Vercel), Bun fits well, and here's the practical reasoning:
Why Bun works for you
- New project = lowest migration cost. The riskiest part of adopting Bun is migrating existing Node code. You have none, so you get the benefits without the pain.
- TypeScript runs natively.
bun run src/index.tsjust works — nots-node, no build step for local dev. That's a real DX win for an Express + TS team. - One toolchain.
bun install(fast, lockfile-aware),bun test(Jest-like API, no Jest/Vitest config), andbun buildreplace three separate tools. Less config drift across the team. - npm packages work. Bun is largely Node-compatible; standard Express and most middleware install and run fine. Commit
bun.lockfor reproducible installs. - Windows is supported. Bun has first-class Windows builds now, so your Windows developers are fine.
- Vercel supports Bun natively. Set
bunVersion: "1.4.x"invercel.json, usebun install --frozen-lockfilein the build, and you're done.
Caveats to plan for
- Not 100% Node-compatible. Native addons and packages relying on Node internals can break. Since you're greenfield, vet dependencies early — if a critical package misbehaves, swap it or fall back.
- Express on Bun is fine, but consider whether you actually need Express: Bun's built-in
Bun.serve(fetch-style handlers) is faster and zero-dependency. If the team prefers Express's middleware ecosystem, that's a legitimate reason to keep it — it works on Bun.
Suggested setup
// vercel.json
{ "bunVersion": "1.4.x" }
bun init
bun add express
bun run src/index.ts # dev, TS runs directly
bun test # built-in test runner
bun install --frozen-lockfile # CI/Vercel
When I'd say "stay with Node" instead
Only if you know you'll depend on native addons (e.g., certain DB drivers, sharp, bcrypt variants) or Node-specific tooling your team can't change. Otherwise, for a fresh Express/TS API on Vercel, Bun is the pragmatic choice — and since your code is standard Node-compatible TS, switching back to Node later is trivial if you ever hit a wall.
bun-runtime--m2
Migration steps
1. Update package.json
{
"name": "api",
"scripts": {
"start": "bun src/index.js"
},
"dependencies": {
"express": "^4.18.0",
"dotenv": "^16.0.0",
"node-fetch": "^2.6.0"
}
}
2. Install dependencies
bun install
This creates a bun.lockb (binary lockfile) and installs into node_modules — no other changes needed.
3. Start the app
bun start # or directly: bun run src/index.js
Code changes (mostly optional)
- CommonJS require: Works as-is. Bun supports
require()natively in.jsfiles, so no rewrite is required. You can migrate to ESM later at your own pace. - dotenv: Bun automatically loads
.envfiles (and.env.local,.env.production, etc.) at startup. You can deleterequire('dotenv').config()entirely. If you keep it, it's harmless — it just re-reads the file. - node-fetch: Bun has native
fetchbuilt in (global). You can dropnode-fetchand usefetch()directly, or keepnode-fetchv2 — it works fine.
Compatibility gotchas
- Express generally works on Bun, but a few middleware patterns hit rough edges:
- Middleware relying on undocumented
req/resinternals or monkey-patching the response object can misbehave. - Some native addons (e.g.,
bcrypt,sharp,canvas) need Bun-compatible builds; pure-JS alternatives (bcryptjs) are safer.
- Middleware relying on undocumented
node-fetchv2 vs v3: v2 is CJS and works; if you ever bump to v3 (ESM-only), make sure your file is loaded as ESM or use nativefetchinstead.- Env var precedence: Bun's built-in
.envloading sets variables before your code runs, soprocess.envis already populated — but it won't override variables already set in the shell unless you use--env-filesemantics carefully. If you relied on dotenv'soverride: trueoption, test that behavior. - Hot reloading:
bun --hot src/index.jsgives you hot reload during dev — a nice bonus, but it's not identical to nodemon semantics (it keeps the process alive and reloads modules). - Lockfile:
bun installignorespackage-lock.jsonand generatesbun.lockb. If you need reproducible CI builds, commit the Bun lockfile. - Node version-specific APIs: Anything using
node:prefixed imports (node:fs, etc.) is fully supported; very new or experimental Node APIs (e.g., somenode:testfeatures) may lag behind.
Minimal path: change the start script, run bun install, run bun start — most Express + CJS apps run unmodified.
Migration steps
-
Install Bun (if not already):
curl -fsSL https://bun.sh/install | bash -
Install dependencies (in your project root):
bun installThis reads your existing
package.jsonand createsbun.lock(commit it). -
Update the start script in
package.json:"scripts": { "start": "bun src/index.js" }Then run:
bun start(Or just
bun src/index.jsdirectly — no script change strictly required.) -
.envloading — Bun auto-loads.envfiles from the project root, sodotenvbecomes optional. You can remove it:bun remove dotenvIf you use a differently-named env file (e.g.
.env.production), pass it explicitly:bun run --env-file=.env.production src/index.jsNote: Bun's auto-loading respects
NODE_ENV(loads.env.development/.env.productionaccordingly). If your code callsrequire('dotenv').config()with a custom path, keep dotenv — it works fine under Bun. -
CommonJS require — no changes needed. Bun supports CommonJS and ESM natively, including
requirein.jsfiles, and even mixing the two.
Compatibility gotchas
- node-fetch v2: works under Bun, but it's largely unnecessary — Bun has native
fetchas a global. You can deleterequire('node-fetch')and usefetch(...)directly, thenbun remove node-fetch. If you keep it, pin awareness: node-fetch v3 is ESM-only and can trip up CJSrequire. - Express: fully supported; no changes needed.
- Native addons: packages with Node C++ addons (
.nodefiles) may fail under Bun. Your deps here are pure JS, so you're fine — but check any transitive deps if you add more. - Not 100% Node-compatible: some less-common
node:APIs or packages relying on Node internals can still break. Test your app's full request paths before switching production traffic. - Lockfile:
bun installgeneratesbun.lock; you can deletepackage-lock.jsonafter verifying everything works. - Version check: run
bun --version— behavior/flags can differ between releases (guidance above targets Bun 1.4.x).
Quick summary of commands
bun install
bun remove dotenv node-fetch # optional cleanups
bun start # or: bun src/index.js
bun-runtime--m4
bunfig.toml
Bun's bunfig.toml doesn't have a dedicated "test runner" section for enabling tests — running bun test picks up *.test.ts automatically. But you can configure useful test and install behavior:
# bunfig.toml
[install]
# Lock the package manager behavior; avoid surprises in CI
exact = true # save exact versions in package.json
frozenLockfile = true # fail if bun.lock is out of sync (good for CI)
[test]
# Files matching these patterns are included (defaults are usually fine)
preload = ["./tests/setup.ts"] # optional global setup file
root = "src" # or wherever your tests live
coverage = false # flip to true if you want coverage reports
coverageThreshold = 0.8
Notes:
preloadreplaces things likejest.setup.js. If you use Testing Library, putimport '@testing-library/jest-dom'(via@testing-library/jest-dom/bunor the standard entry) in your preload file.- There's no
[test]flag to "enable" the runner — it's always built in.
package.json
{
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"test": "bun test",
"test:ci": "bun test --coverage"
}
}
CI (GitHub Actions example)
name: CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- run: bun install --frozen-lockfile
- run: bun test
Vercel gotchas
-
Vercel doesn't run tests during builds. Vercel runs
bun installand your build command only. If you want tests to gate deploys, run them in CI (GitHub Actions) and require that check to pass before merge — don't try to shoehornbun testinto the Vercel build command (it slows every deploy and a flaky test blocks shipping). -
Set the Bun version explicitly. Vercel auto-detects Bun if
bun.lockb/bun.lockexists, but pin the version to match CI. Add topackage.json:{ "packageManager": "bun@1.1.x" }or set the
BUN_VERSIONenv var in your Vercel project settings. Version drift between local/CI/Vercel is the #1 source of "works locally" bugs. -
Install command: Vercel detects Bun from the lockfile and runs
bun installautomatically. If it doesn't, set Install Command tobun install. Don't mix npm/yarn artifacts — deletepackage-lock.json/yarn.lockor Vercel may pick the wrong package manager. -
Build command stays
next build. Bun runs it fine, but if you hit edge-case issues with Next.js + Bun (some plugins/turbopack combos have had rough edges), you can set Build Command tobun run build— same thing, just explicit. -
bun:testimports won't leak into production as long as they're only in*.test.tsfiles — Next's build ignores those. But make sure no production module imports from a test file or abun:test-dependent helper. -
Native modules / postinstall: Bun's install handles
postinstallscripts, but scripts for packages not on Bun's allowlist are skipped by default in newer versions. If a build fails with a missing binary (e.g.,sharp,esbuild), add the package totrustedDependenciesinpackage.json:{ "trustedDependencies": ["sharp"] } -
jsdom/DOM tests:
bun testhas no built-in DOM. If your components tests need a DOM, usehappy-domwith a preload file:// tests/setup.ts import { GlobalRegistrator } from '@happy-dom/global-registrator' GlobalRegistrator.register()and set
preload = ["./tests/setup.ts"]inbunfig.toml.
TL;DR: bunfig.toml mostly configures install + preload behavior; run tests in GitHub Actions with oven-sh/setup-bun, pin the Bun version everywhere, and let Vercel just do bun install + next build.
bunfig.toml
# bunfig.toml — project root
[test]
# files matching these are picked up by `bun test`
preload = ["./tests/setup.ts"] # optional: global test setup
[install]
# exact versions from bun.lock; good for reproducible CI/Vercel builds
exact = true
frozenLockfile = true
Notes:
- Bun auto-discovers
*.test.ts/*.spec.tsfiles — no glob config needed forsrc/utils/format.test.ts. bun:testimports work out of the box; no extra dependency.frozenLockfile = truein[install]makes CI/Vercel installs fail ifbun.lockis out of sync (safer than relying on a CLI flag). Locally you can override withbun install --no-frozen-lockfile.
package.json scripts
{
"scripts": {
"test": "bun test",
"build": "next build"
}
}
Vercel setup
In vercel.json:
{
"bunVersion": "1.4.x"
}
Vercel auto-detects Bun if a bun.lock is present and uses bun install + bun run build for the build command.
CI (GitHub Actions)
- uses: oven-sh/setup-bun@v2
with:
bun-version: 1.4.x
- run: bun install --frozen-lockfile
- run: bun test --parallel
- run: bun run build
Gotchas
- Tests don't run on Vercel deploys — Vercel only builds, it doesn't run your test suite. Run
bun testin CI (GitHub Actions etc.) and gate merges there; Vercel deploys should be triggered only after CI passes (branch protection / merge checks). - Pin the Bun version everywhere —
bunVersioninvercel.json,bun-versionin CI, and ideallypackageManager/enginesinpackage.json. Mismatches between local, CI, and Vercel cause subtle failures. - Commit
bun.lock(text lockfile on Bun 1.4+). Without it,--frozen-lockfileinstalls fail and builds aren't reproducible. If you have an old binarybun.lockb, migrate by runningbun installonce with a recent Bun. bun testis not Jest — the API is Jest-like but not identical.bun:testmocks, snapshot format, and some matchers differ; alsobun testruns everything in a single process by default (use--isolateor--parallelif tests leak globals or share state).- Node-only native modules — if any dependency (or Next.js plugin) relies on Node internals or native addons, verify it works under Bun before relying on it in the build.
next buildunder Bun is generally fine, but test it once locally withbun run build. - Don't set
installCommand/buildCommandmanually unless needed — Vercel's zero-config detection handles Bun; overriding can bypass Bun detection. - Env vars in tests —
bun testloads.envautomatically; be careful not to let test env leak into production builds, and remember Vercel env vars are injected at build/runtime, not from.envfiles.
bun-runtime--m5
Run it with Bun like this:
API_KEY=abc123 bun --hot scripts/check.ts
Notes:
- No ts-node needed — Bun runs TypeScript natively, so
bun scripts/check.tsjust works. - Env var:
API_KEY=abc123before the command sets it for that process. Alternatively, put it in a.envfile in the project root — Bun automatically loads.envfiles, soAPI_KEY=abc123in.envworks with no extra code. - Restart on edit:
--hotenables hot reloading — Bun restarts the file when you save changes. (There's also--watch, which fully restarts the process;--hotkeeps the process alive and re-evaluates the file, which is usually what you want for scripts.)
If your script reads the key via process.env.API_KEY, it'll pick it up automatically.
Bun runs TypeScript natively — no ts-node needed. Just:
API_KEY=abc123 bun --watch scripts/check.ts
bun scripts/check.ts— runs the.tsfile directly (no transpile step, no ts-node).API_KEY=abc123— same inline env var syntax as Node. Alternatively put it in a.envfile and runbun --env-file=.env --watch scripts/check.ts(Bun also auto-loads.envby default).--watch— restarts the process whenever the file (or its imports) change. If you want hot reloading that preserves state where possible, use--hotinstead (mainly useful for servers).
In your script, read the key as usual:
const apiKey = process.env.API_KEY;
if (!apiKey) {
console.error("API_KEY is not set");
process.exit(1);
}
console.log("Key loaded:", apiKey ? "yes" : "no");
One tip: avoid printing the actual key value in logs, even in dev scripts — print a masked version or just whether it's present.
- Results are for the SkillzBench reference agent on GLM-5.3-flash. Switch models above — a skill can help one model and not another.
- Screen tier (1 trial per arm) is directional. Verified needs a full-tier run (≥ 8 tasks, ≥ 3 trials per arm) with the CI excluding zero.
- Task coverage: 7 generated tasks for this skill's category; a skill can shine elsewhere.