+server.ts API endpoint fails to parse body
See original GitHub issueDescribe the bug
The only file new file in the blank svelte-kit project is the +server.ts located in src/routes/api/+server.ts. It just echoes the incoming JSON. Hitting http://localhost:5173/api (with content-type and accept headers set to application/json and body { "sample": "test"} ) will return HTTP 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:
Unexpected end of JSON input
SyntaxError: Unexpected end of JSON input
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 then pnpm dev.
Logs
Sadly there are none.
System Info
System:
OS: Windows 10 10.0.22621
CPU: (16) x64 Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz
Memory: 16.30 GB / 31.92 GB
Binaries:
Node: 19.0.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.19 - C:\Program Files\nodejs\yarn.CMD
npm: 8.19.2 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: Spartan (44.22621.674.0), Chromium (105.0.1343.42)
Internet Explorer: 11.0.22621.1
npmPackages:
vite: ^3.2.0 => 3.2.0
Severity
blocking all usage of SvelteKit
Additional Information
N/A
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:10 (6 by maintainers)
Top Results From Across the Web
HTTPClient POST tries to parse a non-JSON response
I'm trying to make a request in Angular and I know that the HTTP response will not be in JSON ...
Read more >HttpClient 'Http failure during parsing' error for valid json #18396
Request throws an error when trying to parse a response of "ok" which is considered valid ... fix(http): handle string json bodies #18397....
Read more >How to build a REST API with TypeScript using only native ...
First, create an src folder and add an index.ts file. Then, set up a basic TypeScript HTTP server using Node with the following...
Read more >API Reference: ApolloServer - Apollo GraphQL Docs
It does not store query results. Whenever Apollo Server receives an incoming operation, it checks whether that exact operation is present in its...
Read more >How to Use the Fetch API (Correctly) - CODE Magazine
Navigate into the folder Samples-WebAPI and load that folder in Visual Studio Code or Visual Studio 2019. Open the appsettings.json file and ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

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 https://github.com/nodejs/undici/pull/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.
Until #7412 is released, the workaround is to use overrides to force undici@5.11.0.