| name | Bun |
| description | Use when building, testing, or deploying JavaScript/TypeScript applications. Reach for Bun when you need to run scripts, manage packages, bundle code, or test applications with a single unified toolkit. |
| metadata | {"mintlify-proj":"bun","version":"1.0"} |
Bun Skill Reference
Product Summary
Bun is an all-in-one JavaScript/TypeScript toolkit that replaces Node.js, npm, and bundlers with a single binary. It includes a fast runtime (powered by JavaScriptCore), package manager, test runner, and bundler—all optimized for speed and modern JavaScript. Key files: bunfig.toml (configuration), package.json (scripts and dependencies), bun.lock (lockfile). Primary CLI commands: bun run, bun install, bun test, bun build. See https://bun.com/docs for comprehensive documentation.
When to Use
Use Bun when:
- Running TypeScript/JSX files directly without compilation overhead (
bun run file.ts)
- Installing dependencies faster than npm/yarn/pnpm (
bun install)
- Running tests with Jest-compatible syntax (
bun test)
- Bundling JavaScript/TypeScript for browsers or servers (
bun build)
- Executing package.json scripts with minimal startup time
- Building full-stack applications with server and client code
- Setting up monorepos with workspaces
- Developing with hot-reload/watch mode
- Deploying to serverless platforms (Vercel, Railway, AWS Lambda, etc.)
Quick Reference
Core Commands
| Task | Command | Notes |
|---|
| Run TypeScript file | bun run file.ts or bun file.ts | Transpiles on-the-fly; supports JSX |
| Run package script | bun run dev | 28x faster than npm run |
| Install dependencies | bun install | 25x faster than npm; creates bun.lock |
| Add package | bun add react | Adds to package.json and installs |
| Add dev dependency | bun add -d typescript | Installs as devDependency |
| Run tests | bun test | Finds *.test.ts, *.spec.ts files |
| Watch tests | bun test --watch | Re-runs on file changes |
| Build bundle | bun build ./index.ts --outdir ./dist | Bundles for browser/server |
| Watch build | bun build ./index.ts --outdir ./dist --watch | Rebuilds on changes |
| Execute package | bunx cowsay "hello" | Like npx but faster |
Configuration Files
| File | Purpose | Location |
|---|
bunfig.toml | Bun-specific config (runtime, test, install, build) | Project root or ~/.bunfig.toml |
package.json | Scripts, dependencies, workspaces | Project root |
bun.lock | Lockfile (text format by default) | Project root |
tsconfig.json | TypeScript config (Bun respects this) | Project root |
Key bunfig.toml Sections
[define]
"process.env.API_URL" = "'https://api.example.com'"
[test]
root = "./__tests__"
coverage = true
coverageThreshold = 0.9
[install]
optional = true
dev = true
linker = "hoisted"
[run]
shell = "system"
bun = true
Decision Guidance
When to Use Hoisted vs. Isolated Installs
| Scenario | Use | Reason |
|---|
| New monorepo/workspace | isolated | Prevents phantom dependencies |
| New single-package project | hoisted | Traditional npm behavior |
| Existing pre-v1.3.2 project | hoisted | Backward compatibility |
| Strict dependency isolation needed | isolated | Each package gets own node_modules |
Use bun install --linker isolated or set in bunfig.toml.
When to Use bun build vs. bun run
| Task | Use | Why |
|---|
| Execute a script | bun run | Fast startup, no output files |
| Prepare for browser | bun build --target browser | Optimizes for browser APIs |
| Prepare for server | bun build --target bun or --target node | Optimizes for server APIs |
| Create executable | bun build --compile | Single binary with Bun embedded |
| Development server | bun run with Bun.serve() | Direct HTTP server in code |
When to Use --watch vs. --concurrent
| Flag | Use Case |
|---|
bun --watch run dev | Restart entire process on file change |
bun test --concurrent | Run async tests in parallel (faster) |
bun test --watch | Re-run tests on file change |
bun build --watch | Rebuild bundle on file change |
Workflow
1. Initialize a New Project
bun init my-app
cd my-app
2. Install Dependencies
bun install
bun add react
bun add -d @types/react
3. Create and Run Code
bun run index.ts
4. Write Tests
5. Bundle for Production
bun build ./index.ts --outdir ./dist --minify
6. Deploy
Common Gotchas
- Watch mode flag placement: Use
bun --watch run dev, not bun run dev --watch. Flags after the script name are passed to the script itself.
- Node.js compatibility: Bun aims for Node.js compatibility but not everything is implemented. Check nodejs-compat for status.
- Lifecycle scripts security: Bun doesn't execute
postinstall scripts by default. Add trusted packages to trustedDependencies in package.json.
- Lockfile format: Bun v1.2+ uses text
bun.lock by default (not binary bun.lockb). Commit this to version control.
- TypeScript types: If you see
Bun global errors, install @types/bun and configure tsconfig.json with "lib": ["ESNext"].
- Auto-install disabled in production: Set
[install] auto = "disable" in bunfig.toml for CI/CD to prevent unexpected installs.
- Peer dependencies: Bun installs peer dependencies by default (unlike npm). Disable with
[install] peer = false if needed.
- Environment variables: Bun loads
.env, .env.local, .env.[NODE_ENV] automatically. Disable with [env] file = false.
- Monorepo filtering: Use
--filter with glob patterns: bun install --filter 'packages/*' or bun run --filter 'ba*' test.
- Bytecode generation: Only works with
target: "bun". Requires matching Bun version for execution.
Verification Checklist
Before submitting work with Bun:
Resources
For additional documentation and navigation, see: https://bun.com/docs/llms.txt