sveltejs/kit · error

Invalid character escape sequence in ${id}

Error message

Invalid character escape sequence in ${id}

What it means

Inside a route folder's `[u+...]` or `[x+...]` character escape, the hex code must contain only hexadecimal digits. A code with non-hex characters (e.g. `[u+zzzz]`, `[x+g1]`) fails validation and manifest creation throws this error.

Source

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

	/** @type {import('types').PageNode[]} */
	const nodes = [];

	// create route data by processing files in `src/routes`
	if (fs.existsSync(config.files.routes)) {
		/**
		 * @param {number} depth
		 * @param {string} id
		 * @param {string} segment
		 * @param {import('types').RouteData | null} parent
		 */
		const walk = (depth, id, segment, parent) => {
			const unescaped = id.replace(/\[([ux])\+([^\]]+)\]/gi, (match, type, code) => {
				if (match !== match.toLowerCase()) {
					throw new Error(`Character escape sequence in ${id} must be lowercase`);
				}

				if (!/[0-9a-f]+/.test(code)) {
					throw new Error(`Invalid character escape sequence in ${id}`);
				}

				if (type === 'x') {
					if (code.length !== 2) {
						throw new Error(`Hexadecimal escape sequence in ${id} must be two characters`);
					}

					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));
				}
			});

View on GitHub (pinned to 03f1687fe6)

Solutions

  1. Replace the code with valid hex digits only (0-9a-f), e.g. `[u+1f600]`
  2. Look up the actual Unicode codepoint for the character you want
  3. Or drop the escape and use the literal character (or a plain ASCII name) for the folder

Example fix

// before
// src/routes/[u+zzzz]/+page.svelte

// after
// src/routes/[u+1f600]/+page.svelte
Defensive patterns

Strategy: validation

Validate before calling

function isValidEscape(name) {
  return /^\[([x]\+[0-9a-f]{2}|[u]\+[0-9a-f]{4,6})\]$/.test(name);
}
// isValidEscape('[u+1f600]') -> true; isValidEscape('[u+zzzz]') -> false

Try / catch

try {
  await build();
} catch (e) {
  if (String(e.message).includes('Invalid character escape sequence')) {
    console.error('Use only hex digits 0-9a-f inside [x+..] / [u+..]');
  }
  throw e;
}

Prevention

When it happens

Trigger: Directory names like `src/routes/[x+g1]/` or `[u+12g4]/` — the regex matches the escape shape but the code isn't valid hex, so walk() throws during dev/build route scanning.

Common situations: Typos when hand-writing hex escapes; guessing a codepoint instead of looking it up; copying corrupted folder names.

Understand the failure class

Related errors


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