Monorepos
next-bun-compile handles monorepo layouts automatically. The adapter
assembles its traced output tree with the app path preserved
(e.g. apps/web/... relative to the repo root), and the compiled
binary lands at apps/web/server.
One monorepo-specific requirement: Next.js resolves adapterPath
from its own package location, so a nested workspace dependency
needs resolving from the app dir:
import { createRequire } from "node:module";import type { NextConfig } from "next";
const req = createRequire(process.cwd() + "/");
const nextConfig: NextConfig = { adapterPath: req.resolve("next-bun-compile"),};
export default nextConfig;Bun workspaces
Section titled “Bun workspaces”Standard bun workspaces setup, no special config:
// package.json (monorepo root){ "private": true, "workspaces": ["apps/*", "packages/*"]}{ "name": "web", "scripts": { "build": "next build" }, "dependencies": { "@example/shared": "*", "next": "^16.2", "next-bun-compile": "^1" }}bun install # at the monorepo rootcd apps/web && bun run build # produces apps/web/serverA full working monorepo + sharp example is in Recipes › Monorepo + sharp.
pnpm workspaces
Section titled “pnpm workspaces”Same idea — pnpm’s .pnpm/ hoisted store is handled the same way as
bun’s .bun/ store. next-bun-compile walks both.
Turborepo
Section titled “Turborepo”Works as-is. If you use turbo prune --docker in CI to slim the
Docker context, the pruned tree still triggers the nested-layout
codepath. next-bun-compile doesn’t care about the workspace tool — only
about the standalone layout Next.js produces.
What next-bun-compile does for monorepos
Section titled “What next-bun-compile does for monorepos”- Preserves the nested layout. The adapter’s assembled tree keys
files relative to the repo root, so
apps/webnesting survives into the binary’s extraction layout. - Merges split
node_modules/. Traced outputs can place partial package copies at multiple levels; next-bun-compile merges every location per file so nothing is lost to hoisting. - Workspace packages survive. Anything Next.js’s trace pulled in
(including workspace
*-version deps) gets embedded from wherever it landed.
Common gotchas
Section titled “Common gotchas”“Cannot find module ‘next-bun-compile’”
Section titled ““Cannot find module ‘next-bun-compile’””Next resolves the bare adapterPath string from its own package
location, which in a monorepo may not see your app’s nested
dependency. Use the createRequire(process.cwd() + "/") pattern
shown above.
Mixed package managers
Section titled “Mixed package managers”If your CI installs with bun but your repo also has a stale
package-lock.json, Next.js’s “multiple lockfiles” warning may
confuse workspace detection. Remove the unused lockfile.