'failed to fetch' error when the form is empty

19 views Asked by At

Can anyone clarify for me please why when I submit an empty form and the encType is multipart/form-data the request.formData() in the action function throws 'failed to fetch' error? If the encType is application/x-www-form-urlencoded it's OK, I see the empty object as expected.

Form submission:

<Form method="post" encType="multipart/form-data">
    <button>Send</button>
</Form>

The error happens here:

export async function action({ request, params }) {
    request.formData().then(data => {
        console.log(Object.fromEntries(data));
    })
    .catch(err => console.error(err));
    return null;
}

I expected to get an empty object but instead I see the error:

TypeError: Failed to fetch
  at: action
  ...
0

There are 0 answers