Skip to content

Cross-Compilation

Set NBC_TARGET when building to cross-compile for a different platform:

Terminal window
NBC_TARGET=bun-linux-x64 next build

You 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.

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:

Terminal window
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.