Cross-Compilation
Set NBC_TARGET when building to cross-compile for a different
platform:
NBC_TARGET=bun-linux-x64 next buildNBC_TARGET=bun-linux-arm64 next buildNBC_TARGET=bun-darwin-arm64 next buildNBC_TARGET=bun-darwin-x64 next buildNBC_TARGET=bun-windows-x64 next buildYou can wire this into the build script:
{ "scripts": { "build:linux": "next build && NBC_TARGET=bun-linux-x64 next build", "build:mac": "next build && NBC_TARGET=bun-darwin-arm64 next build" }}See the Bun cross-compilation docs for the complete target list and caveats.
Native dependencies + cross-compile
Section titled “Native dependencies + cross-compile”If your app uses native deps like sharp, the binary embeds the
native bindings that were installed for your build platform.
Cross-compiling to a different OS/arch without re-installing the
deps for that platform means those bindings won’t load at runtime.
The reliable approach. Build inside a container matching your deploy platform:
docker run --rm -v "$PWD":/app -w /app oven/bun:1.3.14 bash -c " bun install && bun run build"Or build in CI on a Linux runner if you’re deploying to Linux — that’s what most setups end up doing.