Repository navigation
Description
What version of Bun is running?
1.3.11+af24e281e
What platform is your computer?
Darwin 25.4.0 arm64 arm
What steps can reproduce the bug?
Summary
This was maddening to track down along side my AI companion. I was deeply skeptical of it's outputs until it demonstrated it over and over again and I tried to do other things to get around this. The high level behavior that showed up was my page would render without a bunch of data. We'd find that on server startup supabase client would be returning 0 rows for all my tables, but if I made an innocuous change say to middleware.ts the page would start to be populated. I thought I was losing my mind!
In a Next.js 16.2.0 app, when the server is started under Bun, server-side fetch() requests to a local Supabase/PostgREST endpoint return 200 OK with an empty body during live runtime requests.
The same app and same endpoint work correctly when started under Node.
This also affects @supabase/supabase-js, since it uses fetch under the hood.
Environment
- Bun: 1.3.11
- Node: v22.17.0
- Next.js: 16.2.0
- Runtime target:
next start - Local API target: Supabase/PostgREST at
http://127.0.0.1:54321
Expected behavior
Server-side fetch() in a live Next request should return the same response body that:
- direct shell
fetch()sees - Node
next startsees - direct Node HTTP client sees
Actual behavior under Bun
Inside a live request in next start:
fetch("http://127.0.0.1:54321/rest/v1/categories?select=id", ...)- returns
200 OK - but response body is empty
@supabase/supabase-js on top of that same fetch path returns zero rows.
Control result under Node
Running the same built app under Node:
- same URL
- same headers
- same request path
- returns the expected JSON rows
Minimal observed comparison
Node runtime
- raw
fetch:200, non-empty body supabase-js: expected row count- direct Node HTTP: expected row count
Bun runtime
- raw
fetch:200, empty body supabase-js: zero rows- direct Node HTTP: expected row count
Important detail
This only reproduced when the app was actually started under Bun runtime.
Using a shell wrapper like:
bun run startwas not always a valid control, because in this setup it ultimately launched next start under Node.
The real Bun repro used:
bun ./node_modules/next/dist/bin/next start --hostname 127.0.0.1 --port 55024Repro shape
A request-time route performed all three reads:
- raw
fetchto PostgREST @supabase/supabase-jsusing the default/Next fetch path@supabase/supabase-jsusing a custom Node HTTP fetch implementation
Under Bun:
- (1) returned empty body
- (2) returned zero rows
- (3) returned real rows
Under Node:
- all three returned real rows
Why this matters
This makes server-rendered Next apps under Bun unreliable when talking to local HTTP APIs through fetch, even though:
- the endpoint is healthy
- shell fetch works
- Node runtime works
The issue presents as empty application data rather than a thrown error, which makes it difficult to diagnose.
Reproduction Script
Minimal repro
This repro does not require Supabase.
It uses:
- a tiny localhost HTTP server
- a tiny Next app route
- comparison of Node vs Bun runtime
Repro files
server.mjs
import http from "node:http";
const host = "127.0.0.1";
const port = 54329;
const rows = JSON.stringify([
{ id: "1" },
{ id: "2" },
{ id: "3" },
]);
function writeJson(res, body, extraHeaders = {}) {
res.writeHead(200, {
"content-type": "application/json; charset=utf-8",
"cache-control": "no-store",
...extraHeaders,
});
res.end(body);
}
http
.createServer((req, res) => {
if (req.url === "/rows") {
writeJson(res, rows, {
"content-length": Buffer.byteLength(rows),
});
return;
}
if (req.url === "/rows-chunked") {
res.writeHead(200, {
"content-type": "application/json; charset=utf-8",
"cache-control": "no-store",
connection: "keep-alive",
});
res.write(rows.slice(0, Math.ceil(rows.length / 2)));
setTimeout(() => {
res.end(rows.slice(Math.ceil(rows.length / 2)));
}, 5);
return;
}
if (req.url === "/rows-postgrest-like") {
writeJson(res, `[\n {"id":"1"},\n {"id":"2"},\n {"id":"3"}\n]`, {
connection: "keep-alive",
"content-range": "0-2/*",
vary: "Accept-Encoding",
});
return;
}
res.writeHead(404, {
"content-type": "text/plain; charset=utf-8",
});
res.end("not found");
})
.listen(port, host, () => {
console.log(`upstream listening on http://${host}:${port}`);
});src/app/api/fetch-runtime/route.ts
import http from "node:http";
import { NextResponse } from "next/server";
export const runtime = "nodejs";
const upstreamBase = "http://127.0.0.1:54329";
async function runtimeFetch(path: string) {
const response = await fetch(`${upstreamBase}${path}`, {
cache: "no-store",
});
const text = await response.text();
return {
status: response.status,
bodyLength: text.length,
bodyPreview: text.slice(0, 120),
};
}
async function nodeHttpFetch(path: string) {
const url = new URL(`${upstreamBase}${path}`);
return await new Promise<{
status: number;
bodyLength: number;
bodyPreview: string;
}>((resolve, reject) => {
const request = http.request(url, { method: "GET" }, (response) => {
const chunks: Buffer[] = [];
response.on("data", (chunk) => {
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
});
response.on("end", () => {
const body = Buffer.concat(chunks).toString("utf8");
resolve({
status: response.statusCode ?? 500,
bodyLength: body.length,
bodyPreview: body.slice(0, 120),
});
});
});
request.on("error", reject);
request.end();
});
}
async function compare(path: string) {
const [runtime, nodeHttp] = await Promise.all([
runtimeFetch(path),
nodeHttpFetch(path),
]);
return {
runtime,
nodeHttp,
};
}
export async function GET() {
const [rows, rowsChunked, rowsPostgrestLike] = await Promise.all([
compare("/rows"),
compare("/rows-chunked"),
compare("/rows-postgrest-like"),
]);
return NextResponse.json({
runtime: typeof (globalThis as { Bun?: unknown }).Bun !== "undefined" ? "bun" : "node",
upstreamBase,
rows,
rowsChunked,
rowsPostgrestLike,
});
}Steps
- Start the tiny upstream server:
node server.mjs- Build the Next app:
next build- Start the built app under Node:
node ./node_modules/next/dist/bin/next start --hostname 127.0.0.1 --port 5600- Query the route:
curl -s http://127.0.0.1:5600/api/fetch-runtime- Start the built app under Bun:
bun ./node_modules/next/dist/bin/next start --hostname 127.0.0.1 --port 5601- Query the same route:
curl -s http://127.0.0.1:5601/api/fetch-runtimeExpected
Node and Bun should both return the same response bodies for all three upstream endpoints.
Actual
Node returns the expected bodies for all three endpoints.
Bun returns empty bodies for:
/rows/rows-postgrest-like
but succeeds for:
/rows-chunked
Example output
Node
{
"runtime": "node",
"rows": {
"runtime": { "status": 200, "bodyLength": 34 },
"nodeHttp": { "status": 200, "bodyLength": 34 }
},
"rowsChunked": {
"runtime": { "status": 200, "bodyLength": 34 },
"nodeHttp": { "status": 200, "bodyLength": 34 }
},
"rowsPostgrestLike": {
"runtime": { "status": 200, "bodyLength": 44 },
"nodeHttp": { "status": 200, "bodyLength": 44 }
}
}Bun
{
"runtime": "bun",
"rows": {
"runtime": { "status": 200, "bodyLength": 0, "bodyPreview": "" },
"nodeHttp": { "status": 200, "bodyLength": 34 }
},
"rowsChunked": {
"runtime": { "status": 200, "bodyLength": 34 },
"nodeHttp": { "status": 200, "bodyLength": 34 }
},
"rowsPostgrestLike": {
"runtime": { "status": 200, "bodyLength": 0, "bodyPreview": "" },
"nodeHttp": { "status": 200, "bodyLength": 44 }
}
}Key observation
Inside the same Bun-hosted Next request:
- Next server
fetch()can return200with an empty body - direct Node
httpto the same localhost endpoint returns the correct body
So this appears to be a Bun runtime issue in the Next server fetch path rather than an issue in the upstream server itself.
What is the expected behavior?
See repro steps report
What do you see instead?
See repro steps report
Additional information
No response
Activity
huggsboson commentedon Apr 20, 2026
FWIW I had my AI agent produce the bug report but I did a ton of manual testing of the behavior myself as well and confirmed what it was saying was true.
renatoaraujoc commentedon Jun 27, 2026
I'm having the same issue on 1.3.14,
200 with no body and no content-type, randomly.Had to
globalThis as unknown as { fetch: typeof undiciFetch }).fetch = undiciFetch.Seems like bun's native fetch trips around
await Promise.all[]sometimes.Sad.