sveltejs/kit · error

Invalid route ID ${id}

Error message

Invalid route ID ${id}

What it means

While splitting a route ID into segments, SvelteKit encounters a `[` (or `[[`/`[...`) parameter whose closing delimiter (`]` or `]]`) is missing. This means the route directory/file name has an unbalanced bracket, e.g. src/routes/blog[[category. The manifest generator cannot parse the route and throws during `svelte-kit sync`.

Source

Thrown at packages/kit/src/core/sync/create_manifest_data/sort.js:51

		/** @type {Part[]} */
		const parts = [];

		let i = 0;
		while (i <= id.length) {
			const start = id.indexOf('[', i);
			if (start === -1) {
				parts.push({ type: 'static', content: id.slice(i), matched: false });
				break;
			}

			parts.push({ type: 'static', content: id.slice(i, start), matched: false });

			const type = id[start + 1] === '[' ? 'optional' : id[start + 1] === '.' ? 'rest' : 'required';
			const delimiter = type === 'optional' ? ']]' : ']';
			const end = id.indexOf(delimiter, start);

			if (end === -1) {
				throw new Error(`Invalid route ID ${id}`);
			}

			const content = id.slice(start, (i = end + delimiter.length));

			parts.push({
				type,
				content,
				matched: content.includes('=')
			});
		}

		return parts;
	}

	return routes.sort((route_a, route_b) => {
		const segments_a = split_route_id(route_a.id).map(get_parts);
		const segments_b = split_route_id(route_b.id).map(get_parts);

View on GitHub (pinned to 03f1687fe6)

Solutions

  1. Open the route path reported in the error and add the missing closing bracket: [param] , [[optional]] , or [...rest].
  2. If the parameter is no longer wanted, rename the directory to remove the bracket entirely.
  3. Re-run `svelte-kit sync` (or restart dev server) after fixing to regenerate the manifest.

Example fix

// before
src/routes/blog/[[category/src/routes/blog/[[category]
// after
src/routes/blog/[[category]]/
Defensive patterns

Strategy: validation

Validate before calling

function hasBalancedRouteBrackets(routeId) {
  let i = 0;
  while ((i = routeId.indexOf('[', i)) !== -1) {
    const optional = routeId[i + 1] === '[';
    const delim = optional ? ']]' : ']';
    if (routeId.indexOf(delim, i) === -1) return false;
    i += 1;
  }
  return true;
}
// assert(hasBalancedRouteBrackets('blog/[[category]]'))

Type guard

function isValidRouteId(id) {
  return typeof id === 'string' && [...id.matchAll(/\[/g)].every((m) => id.slice(m.index).includes(id[m.index + 1] === '[' ? ']]' : ']'));
}

Try / catch

try {
  const parts = split(routeId);
} catch (e) {
  if (e.message.startsWith('Invalid route ID')) {
    console.error('Fix unbalanced brackets in:', routeId);
  }
  throw e;
}

Prevention

When it happens

Trigger: A route id containing `[` with no matching `]` or `]]` — e.g. creating the directory src/routes/items[page (missing closing bracket) or a partially-deleted optional parameter [[lang folder.

Common situations: Manually renaming route folders and deleting the closing bracket; shell commands that mangle brackets; merge conflicts leaving half-renamed directories; filesystems or tools that strip/escape brackets.

Related errors


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