-
Notifications
You must be signed in to change notification settings - Fork 2.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
Sveltekit (using vite): cannot read body #6638
Comments
I am seeing the same thing. Tried
|
Has there been any update on this topic? I have experienced this for the first time yesterday. Thank you for an update on this matter. :) |
I did some more investigating. The same result @fiffty describes also happens with const reader = event.request.body.getReader();
const chunks = [];
while(true) {
const { value, done } = await reader.read();
console.log({ value, done });
if (done) {
break;
}
chunks.push(...value);
}
console.log("request body: ", Buffer.from(chunks).toString()); There is just one console log. {
value: Buffer(26) [ 123, 13, 10, 32, 32, 32, 32, 34, 104, 101, 108, 108, 111, 34, 58, 32, 34, 119, 111, 114, 108, 100, 34, 13, 10, 125 ],
done: false,
} However, the second time the request does go through. This is the log of the second time. {
value: Buffer(26) [ 123, 13, 10, 32, 32, 32, 32, 34, 104, 101, 108, 108, 111, 34, 58, 32, 34, 119, 111, 114, 108, 100, 34, 13, 10, 125 ],
done: false,
}
{
value: undefined,
done: true,
}
request body: {
"hello": "world"
} That means that there is something wrong in Bun's Temporary workarondTemporary workaroundFrom my testing, this is a temporary workaround to still read the body. It's probably a really bad workaround that doesn't deal with things like compression, but it's at least something. export const POST = async (event) => {
const reader = event.request.body.getReader();
const contentLength = Number(event.request.headers.get("content-length"));
const chunks = [];
while (true) {
const { value, done } = await reader.read();
if (value) chunks.push(...value);
if (done || chunks.length >= contentLength) break;
}
console.log("request body: ", Buffer.from(chunks).toString());
return new Response(
JSON.stringify({
success: true
})
);
}; |
The new 17 update seems to have resolved this issue. It is now working fine for me. |
Okay, somehow it is still not fixed. Yesterday evening everything worked fine without any workarounds. Now I am logging in to the same setup and it doesnt work anymore. |
Same issue with
|
Same problem. request.json() does not resolve it. I created a simple project to reproduce the problem, but I couldn't. It only occurs in my real project. With the zip provided here I can't reproduce it either. |
In my case the problem occurs with macOS arm64:
|
Has there been any progress on this topic? :) |
What version of Bun is running?
1.0.5 - 1.0.21
What platform is your computer?
Linux 5.4.0-156-generic x86_64 x86_64
What steps can reproduce the bug?
I have a sveltekit project (using vite). I'm running it using
bun --bun run dev
. Here is a zip file that reproduces the issue: sveltekit-bun-body-issue.zipWhen using
--bun
to force vite to use bun's runtime, the promise ofrequest.json()
orrequest.text()
isn't resolved.I see the
1
in the console, but no the2
. Omitting--bun
does work.What is the expected behavior?
To read the body and resolve the promise
What do you see instead?
The promise doesn't get resolved, coursing the request to eventually time out. I don't know if the body is read successfully.
Additional information
When building and then running the project, the body is read successfully. It's just the
vite dev
that doesn't work.The text was updated successfully, but these errors were encountered: