Getting Started
Requirements
Section titled “Requirements”-
Install
Section titled “Install”Terminal window bun add -D next-bun-compileTerminal window npm install -D next-bun-compileTerminal window pnpm add -D next-bun-compileTerminal window yarn add -D next-bun-compile -
Point Next.js at the build adapter
Section titled “Point Next.js at the build adapter”next-bun-compile is a Next.js Build Adapter. Add
adapterPathto yournext.config.ts:import type { NextConfig } from "next";const nextConfig: NextConfig = {adapterPath: "next-bun-compile",};export default nextConfig;No
output: "standalone"needed — the adapter assembles its own traced output tree. You can also enable it without touching the config at all:Terminal window NEXT_ADAPTER_PATH=next-bun-compile next build -
Build the binary
Section titled “Build the binary”Terminal window next buildOne command. Produces a single
./serverexecutable next to yourpackage.json. -
Run it
Section titled “Run it”Terminal window ./serverListens on port 3000 by default. Configurable via the
PORTenv var.
Migrating from the CLI (v0.x)
Section titled “Migrating from the CLI (v0.x)”Three changes:
- Remove
output: "standalone"fromnext.config.tsand addadapterPath: "next-bun-compile". - Change your build script from
next build && next-bun-compileto justnext build. - Cross-compiling?
--target=bun-linux-x64becomesNBC_TARGET=bun-linux-x64 next build.
What’s in the binary?
Section titled “What’s in the binary?”- Your Next.js server runtime (chunks, manifests, build ID)
- Static assets (
.next/static/*) and public files (public/*) - Prerendered pages and their RSC payloads
- All externalized server packages (sharp, prisma, anything in
serverExternalPackages, etc.) - The bun runtime itself (you don’t need bun on the deploy target)
At runtime, static assets and fully-static prerendered pages are
served directly from memory; ISR and cache-component responses get
an in-memory cache that Next’s own revalidation invalidates. The
binary extracts its server runtime files to disk on first run (or to
NBC_RUNTIME_DIR — point it at tmpfs for read-only filesystems), and
skips extraction on subsequent runs of the same build.
Verify it works
Section titled “Verify it works”PORT=3000 ./server &curl http://localhost:3000/You should see your homepage HTML. From here, the typical next step is putting it in a Docker image — see the Distroless + sharp recipe for a complete working Dockerfile.
Next steps
Section titled “Next steps”- Native deps like
sharpneed a runner image with the right C libraries. See Native dependencies in Docker. - Monorepos are supported out of the box. See the Monorepo guide.
- Something went wrong? Check Troubleshooting.
- Curious how the binary actually works? See How it works.