sveltejs/kit · error · Error

Cannot build with ${JSON.stringify(file)} because Bun treats

Error message

Cannot build with ${JSON.stringify(file)} because Bun treats a route segment starting with `:` as a parameter. Rename the file or route so no segment starts with `:`.

What it means

adapter-bun rejects route paths where any segment starts with ':' because Bun's router treats a leading colon as a dynamic parameter placeholder, which would collide with the literal colon in the emitted file path (and browsers request the colon raw, unencoded).

Source

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

	if (precompress) {
		if (fs.existsSync(`${file}.br`)) meta.br = true;
		if (fs.existsSync(`${file}.gz`)) meta.gz = true;
	}

	return meta;
}

/** @param {string[]} files */
function validate_file_paths(files) {
	for (const file of files) {
		if (file.includes('*')) {
			throw new Error(
				`Cannot build with ${JSON.stringify(file)} because Bun treats literal \`*\` characters in route paths as wildcards. Rename the file or route to remove the \`*\` character.`
			);
		}
		// a leading ':' would need percent-encoding, but browsers request the colon raw
		if (file.split('/').some((segment) => segment.startsWith(':'))) {
			throw new Error(
				`Cannot build with ${JSON.stringify(file)} because Bun treats a route segment starting with \`:\` as a parameter. Rename the file or route so no segment starts with \`:\`.`
			);
		}
	}
}

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

	return {
		name: '@sveltejs/adapter-bun',

View on GitHub (pinned to 03f1687fe6)

Solutions

  1. Rename the segment to SvelteKit's dynamic route syntax: src/routes/[id]/ instead of src/routes/:id/.
  2. Audit src/routes for any file or folder whose name starts with ':'.
  3. Use a different adapter (e.g. adapter-node) if ':'-prefixed paths are genuinely required.

Example fix

// before
src/routes/:id/+page.svelte
// after
src/routes/[id]/+page.svelte
Defensive patterns

Strategy: validation

Validate before calling

import fs from 'node:fs';
import path from 'node:path';
const bad = [];
(function walk(dir) {
  for (const seg of fs.readdirSync(dir)) {
    const p = path.join(dir, seg);
    if (fs.statSync(p).isDirectory()) {
      if (seg.startsWith(':')) bad.push(p);
      walk(p);
    }
  }
})('src/routes');
if (bad.length) throw new Error(`Rename ':'-prefixed route segments: ${bad.join(', ')}`);

Type guard

const isBunSafeRoute = (file) => !file.split('/').some((s) => s.startsWith(':'));

Try / catch

try {
  await build();
} catch (e) {
  if (/segment starting with `:` as a parameter/.test(e.message)) {
    console.error('Convert :x route segments to [x] SvelteKit bracket syntax');
    process.exit(1);
  }
  throw e;
}

Prevention

When it happens

Trigger: validate_file_paths splits the generated route file path on '/' and any segment begins with ':', e.g. a file/folder literally named ':id' under src/routes.

Common situations: A route directory or file accidentally named with a leading colon (e.g. src/routes/:id/+page.svelte) instead of SvelteKit's bracket syntax [id]; route folder names copied from another framework (Express/Next.js ':param' style).

Related errors


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