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
- Fix the param definition syntax: parameters must look like `[name]`, `[name=matcher]`, with valid optional/remainder modifiers (`[name]` vs `[[name]]`, `[...rest]`).
- Ensure any referenced matcher exists as a named export in `src/params/<matcher>.js`.
- Log/print the definition string passed to `normalize_param_definition` to spot the malformed input.
- Validate dynamically-built definitions before use with a regex like /^\[+\.{0,3}[a-zA-Z_][a-zA-Z0-9_]*(=[a-zA-Z0-9_-]+)?\+?\]$/.
- 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
- Validate param strings against a strict regex before normalization.
- Ensure referenced matchers exist in src/params/.
- Escape or validate interpolated values when building definitions dynamically.
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
- Invalid route ID ${id}
- Missing params for dynamic route ID ${id}
- Files prefixed with + are reserved (saw ${project_relative})
- Only Svelte files can reference named layouts. Remove '${mat
- Files and directories prefixed with + are reserved (saw ${pr
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/3ccd35e36cd4347b.
Report an issue: GitHub.