sveltejs/kit · error · Error

Invalid param definition

Error message

Invalid param definition

What it means

`normalize_param_definition` parses parameter definitions used by SvelteKit's param-matching API. When the definition string cannot be tokenized/normalized into a valid structure, this generic error is thrown, usually meaning the parameter syntax (modifiers, types, matchers like `[name=int]` or `[name=matcher]`) is malformed.

Source

Thrown at packages/kit/src/exports/params/index.js:69

			/** @type {unknown} */ ({
				'~standard': {
					validate(/** @type {unknown} */ value) {
						const result = definition(/** @type {string} */ (value));

						if (result === undefined) {
							return { issues: [{ message: 'Invalid param' }] };
						}

						if (/** @type {any} */ (result) instanceof Promise) return result; // will be validated and rejected upstream

						return { value: result };
					}
				}
			})
		);
	}

	throw new Error('Invalid param definition');
}

View on GitHub (pinned to 03f1687fe6)

Solutions

  1. Fix the param definition syntax: parameters must look like `[name]`, `[name=matcher]`, with valid optional/remainder modifiers (`[name]` vs `[[name]]`, `[...rest]`).
  2. Ensure any referenced matcher exists as a named export in `src/params/<matcher>.js`.
  3. Log/print the definition string passed to `normalize_param_definition` to spot the malformed input.
  4. Validate dynamically-built definitions before use with a regex like /^\[+\.{0,3}[a-zA-Z_][a-zA-Z0-9_]*(=[a-zA-Z0-9_-]+)?\+?\]$/.
  5. If using `defineParams`, check each definition entry individually to isolate the failing one.

Example fix

// before
const def = `[id=${matcherName}`; // missing closing bracket
normalize_param_definition(def);
// after
const def = `[id=${matcherName}]`;
normalize_param_definition(def);
Defensive patterns

Strategy: validation

Validate before calling

const PARAM_RE = /^\[{1,2}(?:\.\.\.)?[a-zA-Z_][a-zA-Z0-9_]*(?:=[a-zA-Z0-9_-]+)?\]{1,2}$/;
function isValidParamDefinition(def) {
  return PARAM_RE.test(def);
}
if (!isValidParamDefinition(def)) console.error('bad param definition:', def);

Try / catch

try {
  normalize_param_definition(def);
} catch (e) {
  if (e.message === 'Invalid param definition') {
    throw new Error(`Malformed param definition "${def}" — check brackets, name, and matcher`);
  }
  throw e;
}

Prevention

When it happens

Trigger: Malformed bracket syntax in route param definitions — e.g. unmatched brackets, empty param names, unknown modifiers, or invalid matcher references when using `defineParams`/custom param normalization.

Common situations: Typo in a route like `/blog/[id` (missing `]`); referencing a matcher file that doesn't exist or has a bad name; hand-writing param definitions programmatically with incorrect interpolation.

Related errors


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