[Bug?]: Could not parse content as FormData on AWS Lambda
Duplicates
- [X] I have searched the existing issues
Latest version
- [X] I have tested the latest version
Current behavior 😯
When deploying to AWS Lambda and submitting a form in an application the submission fails and returns at HTTP 500.
This occurs even with a simple form and corresponding action
import {formAction} from '~/server';
export default function FormPage() {
return (
<main>
<h1>Form</h1>
<form action={formAction} method='post'>
<label for="name">Name</label>
<input type="text" name="name" id="name-input" />
<label for="name">Password</label>
<input type="password" name="name" id="password-input" />
<button type="submit">
Submit
</button>
</form>
</main>
);
}
export async function formTest(formData: FormData) {
const name = String(formData.get('name'));
const password = String(formData.get('password'));
console.log(name, password);
throw redirect('/');
}
...
export const formAction = action(formTest, 'form-action');
The form fails and responds with a HTTP500 and the following error:
_Request.formData: Could not parse content as FormData.
The full traceback
at webidl.errors.exception (node:internal/deps/undici/undici:1432:14) at _Request.formData (node:internal/deps/undici/undici:4505:33) at async Object.D$2 [as handler] (./server/chunks/nitro/aws-lambda.mjs:7596:14) at async Object.handler (./server/chunks/nitro/aws-lambda.mjs:3471:19) at async toNodeHandle (./server/chunks/nitro/aws-lambda.mjs:3660:7) at async Runtime.handler (./server/chunks/nitro/aws-lambda.mjs:8890:13) | 2024-01-28T16:03:43.140Z ec66aefc-a464-426b-a65b-a99ae9dbcfdd ERROR [nitro] [request error] [unhandled] _Request.formData: Could not parse content as FormData. at webidl.errors.exception (node:internal/deps/undici/undici:1432:14) at _Request.formData (node:internal/deps/undici/undici:4505:33) at async Object.D$2 [as handler] (./server/chunks/nitro/aws-lambda.mjs:7596:14) at async Object.handler (./server/chunks/nitro/aws-lambda.mjs:3471:19) at async toNodeHandle (./server/chunks/nitro/aws-lambda.mjs:3660:7) at async Runtime.handler (./server/chunks/nitro/aws-lambda.mjs:8890:13)
The form data fields appear to passing to the body correctly. Perhaps there is something in the Lambda node runtime that im missing?
Forms work fine in the local development server and when building to node.
Expected behavior 🤔
Forms should submit normally.
Steps to reproduce 🕹
An minimal reproducible example repo is available here:
https://github.com/russbiggs/solid-start-form-lambda
This include AWS CDK for deploying to AWS lambda and generating an public URL.
Context 🔦
Attempting to deploy a solid-start application with forms on AWS lambda.
Your environment 🌎
System:
OS: MacOS Ventura 13.1
Arch: Apple M1 arm64
Binaries:
Node: v18.15.0
npm: 9.8.1
npmPackages:
vinxi: 0.1.10
solid-js: 1.8.12
@solidjs/meta: "^0.29.2",
@solidjs/router: "^0.10.10",
@solidjs/start: "^0.4.11",
This issue seems to be have been resolved somewhere between vinxi 0.1.10 and 0.3.10 and/or solid start 0.4.11 and 0.7.5. Running the demo repo listed above on lambda with the updated version does seem to submit as expected.
Awesome. Thanks.