sveltejs/kit · error
Form cannot contain duplicated keys — "${field.name}" has ${
Error message
Form cannot contain duplicated keys — "${field.name}" has ${entries.length} values What it means
convert_formdata turns submitted FormData into the typed form object. A non-array field must yield exactly one value; when the same encoded field key appears with multiple entries and the field was not declared as an array, the conversion is ambiguous and the library throws.
Source
Thrown at packages/kit/src/runtime/form-utils.js:100
*/
export function convert_formdata(form_id, data) {
/** @type {Record<string, any>} */
const result = {};
for (const field_name of data.keys()) {
/** @type {any[]} */
const values = data.getAll(field_name);
const field = parse_form_key(form_id, field_name);
// an empty `<input type="file">` will submit a non-existent file, bizarrely
const entries = values.filter(
(entry) => typeof entry === 'string' || entry.name !== '' || entry.size > 0
);
if (entries.length === 0 && !field.is_array) continue;
if (entries.length > 1 && !field.is_array) {
throw new Error(
`Form cannot contain duplicated keys — "${field.name}" has ${entries.length} values`
);
}
set_nested_value(
result,
field,
coerce_form_value(field.type, field.is_array ? entries : entries[0])
);
}
return result;
}
export const BINARY_FORM_CONTENT_TYPE = 'application/x-sveltekit-formdata';
const BINARY_FORM_VERSION = 0;
const HEADER_BYTES = 1 + 4 + 2;
/**View on GitHub (pinned to 03f1687fe6)
Solutions
- Ensure each scalar field name appears exactly once in the form, removing duplicate inputs.
- If multiple values are intended, declare the field as an array (array field variant of form.fields.as).
- For multi-select, use the matching array field type so multiple entries are accepted.
Example fix
// before
<input name={fields.tag.as('tag')} />
<input name={fields.tag.as('tag')} />
// after
<input name={fields.tags.as('tags', { array: true })} multiple /> Defensive patterns
Strategy: validation
Validate before calling
const counts = {};
for (const [key] of new FormData(form).entries()) counts[key] = (counts[key] ?? 0) + 1;
const dupes = Object.entries(counts).filter(([, n]) => n > 1 && !isArrayField(keyOf(n)));
if (dupes.length) throw new Error(`duplicated scalar fields: ${dupes.map(([k]) => k).join(', ')}`); Prevention
- Give each scalar input a unique generated name.
- Use array field declarations when the same key legitimately posts multiple values.
- Check for duplicated markup when rendering both enhanced and no-JS fallback forms.
When it happens
Trigger: Submitting a form where a scalar field's name is duplicated (two inputs sharing the same generated name) while the field was created without array semantics; accidentally rendering an input twice (e.g. once in a modal and once in the base form).
Common situations: Copy-pasted inputs with identical names; a select multiple posting multiple values into a scalar field; duplicated markup from both no-JS fallback and enhanced layers both rendering the field.
Related errors
- Invalid array key ${keys[i + 1]}
- use:enhance can only be used on <form> fields with method="P
- Your form contains <input type="file"> fields, but is missin
- A form object can only be attached to a single `<form>` elem
- Multiple overrides for the same query are not allowed in a s
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/1fdf3796734c28f8.
Report an issue: GitHub.