sveltejs/kit · error
Your form contains <input type="file"> fields, but is missin
Error message
Your form contains <input type="file"> fields, but is missing the necessary `enctype="multipart/form-data"` attribute. This will lead to inconsistent behavior between enhanced and native forms. For more details, see https://github.com/sveltejs/kit/issues/9819.
What it means
When a remote form's enctype is not multipart/form-data but the submitted FormData contains File values, enhanced and native submissions would behave inconsistently (native forms would silently drop or mis-encode files). SvelteKit throws in validate_form_data to surface this mismatch early.
Source
Thrown at packages/kit/src/runtime/client/remote-functions/form.svelte.js:841
}
/**
* @param {FormData} form_data
* @param {string} enctype
*/
function validate_form_data(form_data, enctype) {
for (const key of form_data.keys()) {
if (/^\$[.[]?/.test(key)) {
throw new Error(
'`$` is used to collect all FormData validation issues and cannot be used as the `name` of a form control'
);
}
}
if (enctype !== 'multipart/form-data') {
for (const value of form_data.values()) {
if (value instanceof File) {
throw new Error(
'Your form contains <input type="file"> fields, but is missing the necessary `enctype="multipart/form-data"` attribute. This will lead to inconsistent behavior between enhanced and native forms. For more details, see https://github.com/sveltejs/kit/issues/9819.'
);
}
}
}
}
View on GitHub (pinned to 03f1687fe6)
Solutions
- Add enctype="multipart/form-data" to the <form> element
- Remove the file input if file upload is not intended
- Handle the file via a separate upload endpoint/form with the correct enctype
Example fix
// before <form method="POST" use:enhance> <input type="file" name="doc" /> </form> // after <form method="POST" enctype="multipart/form-data" use:enhance> <input type="file" name="doc" /> </form>
Defensive patterns
Strategy: validation
Validate before calling
function needsMultipart(form) {
return form.enctype !== 'multipart/form-data' &&
form.querySelectorAll('input[type="file"]').length > 0;
}
// if true, set enctype before submit Prevention
- Add enctype="multipart/form-data" whenever a form contains file inputs
- Re-check enctype after adding file inputs to existing forms
- Cover file-upload forms with a submit test
When it happens
Trigger: Adding <input type="file"> to a <form> whose enctype remains the default application/x-www-form-urlencoded (or is unset), then submitting the enhanced remote form.
Common situations: Retrofitting a file upload into an existing text-only form without updating enctype; forgetting enctype on forms that grew file inputs over time; see sveltejs/kit#9819.
Related errors
- Can only use the `multiple` attribute when `name` includes a
- Cannot mix and match file and non-file inputs under the same
- `$` is used to collect all FormData validation issues and ca
- Your form contains <input type="file"> fields, but is missin
- Cannot call submit() before the form is attached
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/f85763cf1c8dcb6f.
Report an issue: GitHub.