Crash "TypeError: serverFn is not a function" when calling server function with nested server function multiple times #6451
Send to my agentWhich project does this relate to?#
Start
Describe the bug#
Sometimes TanStack Start crashes on this line with the following error when calling a specific server function multiple times at nearly the same time:
return serverFn(...args)
^
TypeError: serverFn is not a function
at Object.fn (/Users/ulrichstark/Desktop/tanstack-repro-crash-serverfn-is-not-a-function/node_modules/@tanstack/start-server-core/src/createSsrRpc.ts:18:12)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async client (/Users/ulrichstark/Desktop/tanstack-repro-crash-serverfn-is-not-a-function/node_modules/@tanstack/start-client-core/src/createServerFn.ts:786:21)
at async callNextMiddleware (/Users/ulrichstark/Desktop/tanstack-repro-crash-serverfn-is-not-a-function/node_modules/@tanstack/start-client-core/src/createServerFn.ts:282:24)
at async Object.assign (/Users/ulrichstark/Desktop/tanstack-repro-crash-serverfn-is-not-a-function/node_modules/@tanstack/start-client-core/src/createServerFn.ts:120:26)
Your Example Website or App#
https://github.com/ulrichstark/tanstack-repro-crash-serverfn-is-not-a-function
Steps to Reproduce the Bug or Issue#
git clone https://github.com/ulrichstark/tanstack-repro-crash-serverfn-is-not-a-function
cd tanstack-repro-crash-serverfn-is-not-a-function
npm i
npx vite
Expected behavior#
Don't crash
Screenshots or Videos#
No response
Platform#
- Router / Start Version: 1.154.7
- OS: macOS
- Browser: Chrome
- Browser Version: 143.0.7499.170
- Bundler: Vite
- Bundler Version: 7.3.1
Additional context#
Clicking the button in my repro calls the server function uploadDocumentServerFn 100 times. This server function calls the imported server function analyzeDocumentServerFn. And this server function uses and imports getCookies from @tanstack/react-start and zodTextFormat from openai.
Sometimes the button doesn't trigger the crash, so just click it again until the dev server crashes.
I don't think I'm able to remove more stuff from my repro project while still getting the dev server to crash on button click. I also noticed that when removing the @tailwindcss/vite plugin from vite.config.ts, the crash goes away.
Having the same issue in my project. Calling a server function (it returns a session from '@tanstack/react-start/server') in my root router loader throws the same error occasionally.
Same
Getting this error when saving files.
I do struggle with it from time to time on HMR, seems like clearing circular deps helps
I'm also experiencing this error sometimes.
When it starts happening, it happens on every page load.
I'm running my dev server inside an Ubuntu WSL on Win 11. Sometimes the error goes away after closing VSCode + terminating the WSL (
wsl -t ubuntu) + restarting VSCode & the dev server. However, that doesn't always help & when it doesn't I have to restart my whole computer to make the error go away...I wasn't able yet to figure out what server fn causes this and therefore can't tell whether or not I'm also dealing with nested server fns like the OP.
Sheraff(GitHub profile, opens in a new tab) linked this to #8817
Sign in to join this conversation.
In our real world project, where my minimal repro of this issues comes from, I also sometimes see the following error under the same circumstances:
So my issue might be related to #6056.