sveltejs/kit · error · Error

adapter-bun requires running the SvelteKit build with Bun. U

Error message

adapter-bun requires running the SvelteKit build with Bun. Use `bun run --bun build`.

What it means

adapter-bun's adapt step relies on Bun-specific APIs (the global Bun object) to build its output. If the build is executed with Node.js instead of Bun, the global is undefined and the adapter throws immediately before producing any output.

Source

Thrown at packages/adapter-bun/index.js:116

		}
	}
}

/** @type {import('./index.js').default} */
export default function (opts = {}) {
	const {
		out = 'build',
		envPrefix = '',
		precompress = false,
		serverOptions = {},
		buildOptions = {}
	} = opts;

	return {
		name: '@sveltejs/adapter-bun',
		async adapt(builder) {
			if (typeof Bun === 'undefined') {
				throw new Error(
					'adapter-bun requires running the SvelteKit build with Bun. Use `bun run --bun build`.'
				);
			}

			fs.rmSync(out, { recursive: true, force: true });

			builder.log.minor('Building server');

			if (precompress && buildOptions.compile) {
				builder.log.warn(
					'precompress is ignored with buildOptions.compile: embedded assets are imported by identity path'
				);
			}

			const server = builder.getServerDirectory();

			const src_dir = path.resolve(import.meta.dirname, 'src');
			const index_file = path.resolve(src_dir, 'index.js');

View on GitHub (pinned to 03f1687fe6)

Solutions

  1. Run the build with Bun: `bun run --bun build` (or `bun --bun vite build`).
  2. Install Bun first: curl -fsSL https://bun.sh/install | bash, then rerun the build.
  3. In CI, use a Bun setup action (oven-sh/setup-bun) before the build step.
  4. Use adapter-node instead if you intend to build and run with Node.

Example fix

// before
npm run build   // runs vite build under Node
// after
bun install
bun run --bun build
Defensive patterns

Strategy: validation

Validate before calling

if (typeof Bun === 'undefined') {
  throw new Error('This project builds with adapter-bun — run `bun run --bun build` instead of npm/node.');
}

Type guard

const isBunRuntime = () => typeof globalThis.Bun !== 'undefined';

Try / catch

try {
  await build();
} catch (e) {
  if (/requires running the SvelteKit build with Bun/.test(e.message)) {
    console.error('Rerun with: bun run --bun build');
    process.exit(1);
  }
  throw e;
}

Prevention

When it happens

Trigger: Running `vite build` / `npm run build` with Node as the runtime so `typeof Bun === 'undefined'` inside adapt(builder).

Common situations: CI configured with a Node setup step and no Bun runtime; running the default npm script instead of the Bun one; Bun not installed locally.

Related errors


AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02). Data as JSON: /api/errors/4b7c42cfd55bf6c2. Report an issue: GitHub.