Raw Response from server function not working on Bun runtime #5255
Send to my agentWhich project does this relate to?#
Start
Describe the bug#
When running with Bun as a runtime (e.g bun --bun run dev), returning a Response object from a server function throws an error.
const expectedValue = 'Hello from a server function!'
export const rawResponseFn = createServerFn().handler(() => {
return new Response(expectedValue)
})
Uncaught (in promise) Error: Invariant failed: expected content-type header to be set
at invariant (tiny-invariant.js?v=ff4058f6:12:9)
at getResponse (serverFnFetcher.js?v=ff4058f6:104:3)
at async serverFnFetcher (serverFnFetcher.js?v=ff4058f6:43:12)
at async client (createServerFn.js?v=ff4058f6:205:21)
at async onClick (demo.start.raw-response.tsx:32:28)
See for example this e2e component. It works with node, but not Bun
Your Example Website or App#
Steps to Reproduce the Bug or Issue#
- Create new Start app
- Create a component with a server function that returns a
Response - Run dev server with Bun runtime:
bun --bun run dev - Visit site and trigger the call to the function
Expected behavior#
Response
Screenshots or Videos#
No response
Platform#
- Router / Start Version: 1.132.7
- OS: Linux
- Browser: Chrome
- Browser Version: 140
- Bundler: vite
- Bundler Version: 6.3.6
- Runtime: Bun
- Runtime Version: 1.2.22
Additional context#
No response
Just tried with Bun 1.2.23 and @tanstack/react-start@1.132.19. The same bug.
The problem is that the response from the server function comes with missing headers (e.g.
content-type) when running with Bun runtime (bun --bun run dev), whereas when running with Node (bun run dev) it does.Bun response headers
HTTP/1.1 200 OK Vary: Origin Date: Sun, 28 Sep 2025 15:53:01 GMT Transfer-Encoding: chunkedNode response headers
HTTP/1.1 200 Vary: Origin content-type: text/plain;charset=UTF-8 Date: Sun, 28 Sep 2025 15:57:13 GMT Connection: keep-alive Keep-Alive: timeout=5 Transfer-Encoding: chunked@jph-sw Could you please confirm that when running with
bun --bun run devthe "raw response" example response comes with thecontent-typeheader set?@pricci1 It was an error on my part.
Sign in to join this conversation.
Works for me on 1.132.9