Undici crash when using form data and blobs in server functions
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 15.1k
- Forks
- 1.9k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 143
Description
Which project does this relate to?
Start
Describe the bug
(Tested react-start 1.139.12, nodejs 24.11, undici 7.16 (installed through npm and not using the nodejs' bundled version))
When trying to send a form data object containing a blob using undici.request from a server action the call crashes with the following error
Server Fn Error!
TypeError: Cannot read properties of null (reading 'byteLength')
at Object.pull (node:internal/deps/undici/undici:6191:24)
at invokePromiseCallback (node:internal/webstreams/util:172:10)
at Object.<anonymous> (node:internal/webstreams/util:177:23)
at readableByteStreamControllerCallPullIfNeeded (node:internal/webstreams/readablestream:3145:24)
at readableByteStreamControllerPullSteps (node:internal/webstreams/readablestream:3254:3)
at [kPull] (node:internal/webstreams/readablestream:1201:5)
at readableStreamDefaultReaderRead (node:internal/webstreams/readablestream:2269:39)
at nextSteps (node:internal/webstreams/readablestream:493:7)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async writeIterable (node:internal/deps/undici/undici:7485:26)
With the following example code
import { createServerFn } from '@tanstack/react-start'
import * as undici from 'undici';
import * as fs from 'node:fs';
export const doFetch = createServerFn({ method: 'GET' }).handler(async () => {
const data = new undici.FormData();
data.append(
'document',
await fs.openAsBlob('./package.json'),
'package.json'
);
// This function call here is throwing
const response = await undici.request('http://localhost:3000', {
body: data,
method: 'POST',
});
console.log(response.statusCode, await response.body.text());
})
This code is valid and works correctly when ran through node's repl:
: node
Welcome to Node.js v24.11.0.
Type ".help" for more information.
> const { doFetch } = await import('./src/action.ts')
undefined
> await doFetch()
404 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot POST /</pre>
</body>
</html>
undefined
>
I suspect this might have to do with some global patching of the Blob class maybe ? I'm not entirely sure really
Your Example Website or App
https://github.com/Zuruuh/tanstack-start-undici-repro
Steps to Reproduce the Bug or Issue
- Press the button on the reproducer and check the terminal
Expected behavior
The http call should succeed
Screenshots or Videos
No response
Platform
- Router / Start Version: 1.139.12
- OS: Reproduced on WSL and MacOS
- Browser: Reproduced on Chrome and Firefox (both latest)
- Bundler: vite
- Bundler Version: 7.2.6
Additional context
I'm not sure wether this is an issue with tanstack start or undici really, but given that the same function works outside of start I think it's worth reporting here
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked tanstack-start-undici-repro and reproduce the crash by pressing the button, then compare the server-function behavior with the provided Node REPL example. Trace how the FormData and Blob are handled in the server-function environment; done means the request completes successfully and returns the expected response.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, typescript, vite
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100