-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
+server.ts API endpoint fails to parse body #7409
Comments
I ran into the exact same issue today setting up a new Sveltekit project and am on MacOS, so it's probably not a Windows issue. It might be related to #5370, because I am seeing the same error "Invalid request body" |
Oddly, I can reproduce this by cloning the repo, but as soon as I add a pnpm override to start debugging it, it works... a true Heisenbug 🤔 |
Thanks for the response - I almost went crazy trying out different things for this seemingly straight-forward thing! |
I think this is due to the new version of undici that was just released a few hours ago. Its |
Yeah, when I override to 5.11.0, things seem to work fine. The obvious change in 5.12.0 that would be causing this is nodejs/undici#1681 but I haven't dug any further into what this was intended to do or whether this is a new bug there or what. |
I'm marking this as urgent. It might be a good idea to pin to undici 5.11.0 if we can't immediately see how we should now be calling |
Yep, I can confirm pinning |
This change is expected, see |
Is there a work around or will the patch be coming soon? |
Until #7412 is released, the workaround is to use overrides to force undici@5.11.0. |
Describe the bug
The only file new file in the blank svelte-kit project is the
+server.ts
located insrc/routes/api/+server.ts
. It just echoes the incoming JSON. Hittinghttp://localhost:5173/api
(withcontent-type
andaccept
headers set toapplication/json
and body{ "sample": "test"}
) will returnHTTP 400 Bad request
-> and the request never hits the API endpoint.If I remove the content-type and accept headers it will enter the API endpoint but it would error out on
await request.json()
with:It might be a Windows issue but honestly I am not sure and can't test atm.
Reproduction
https://github.com/callmeberzerker/body-not-working
Run
pnpm install
and thenpnpm dev
.Logs
System Info
Severity
blocking all usage of SvelteKit
Additional Information
N/A
The text was updated successfully, but these errors were encountered: