sveltejs/kit · error

Invalid route ${id} — brackets are unbalanced

Error message

Invalid route ${id} — brackets are unbalanced

What it means

Route ID validation error: the number of '[' characters in the route id does not equal the number of ']' characters, so a dynamic/optional/rest parameter group is opened but never closed (or vice versa), e.g. a directory named [slug or [slug]]. Fires while walking src/routes during sync/dev.

Source

Thrown at packages/kit/src/core/sync/create_manifest_data/index.js:171

					return String.fromCharCode(parseInt(code, 16));
				} else {
					if (code.length < 4 || code.length > 6) {
						throw new Error(
							`Unicode escape sequence in ${id} must be between four and six characters`
						);
					}

					return String.fromCodePoint(parseInt(code, 16));
				}
			});

			if (/\]\[/.test(unescaped)) {
				throw new Error(`Invalid route ${id} — parameters must be separated`);
			}

			if (count_occurrences('[', id) !== count_occurrences(']', id)) {
				throw new Error(`Invalid route ${id} — brackets are unbalanced`);
			}

			if (/#/.test(segment)) {
				// Vite will barf on files with # in them
				throw new Error(`Route ${id} should be renamed to ${id.replace(/#/g, '[x+23]')}`);
			}

			if (/\[\.\.\.[\w-]+\]\/\[\[/.test(id)) {
				throw new Error(
					`Invalid route ${id} — an [[optional]] route segment cannot follow a [...rest] route segment`
				);
			}

			if (/\[\[\.\.\./.test(id)) {
				throw new Error(
					`Invalid route ${id} — a rest route segment is always optional, remove the outer square brackets`
				);
			}

View on GitHub (pinned to 03f1687fe6)

Solutions

  1. Rename the route file or directory so every '[' has a matching ']'
  2. Check for accidentally truncated parameter names in nested directories
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/kit/src/core/sync/create_manifest_data/index.js:171 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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