Skip to content

Raw Response from server function not working on Bun runtime #5255

@pricci1

Description

@pricci1

Which 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

https://github.com/TanStack/router/blob/0babe5d805ae18a7624f54eb6948d59ba10f5715/e2e/react-start/server-functions/src/routes/raw-response.tsx

Your Example Website or App

https://github.com/TanStack/router/blob/0babe5d805ae18a7624f54eb6948d59ba10f5715/e2e/react-start/server-functions/src/routes/raw-response.tsx

Steps to Reproduce the Bug or Issue

  1. Create new Start app
  2. Create a component with a server function that returns a Response
  3. Run dev server with Bun runtime: bun --bun run dev
  4. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions