Skip to content
Source
Sign inSign up
TanStack/router

Crash "TypeError: serverFn is not a function" when calling server function with nested server function multiple times #6451

Send to my agent
Openulrichstark(GitHub profile, opens in a new tab) opened this issue 6 comments

Which 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.

  1. 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:

    Server Fn Error!
    
    TypeError: action is not a function
        at eval (/real-world-project/node_modules/@tanstack/start-server-core/src/server-functions-handler.ts:152:22)
        at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
        at async eval (/real-world-project/node_modules/@tanstack/start-server-core/src/server-functions-handler.ts:75:17)
        at async handleServerAction (/real-world-project/node_modules/@tanstack/start-server-core/src/server-functions-handler.ts:73:20)
        at async next (/real-world-project/node_modules/@tanstack/start-server-core/src/createStartHandler.ts:165:16)
        at async startRequestResolver (/real-world-project/node_modules/@tanstack/start-server-core/src/createStartHandler.ts:314:21)
        at async Object.fetch (/real-world-project/node_modules/@tanstack/react-start/src/default-entry/server.ts:16:14)
        at async Object.fetch (/real-world-project/node_modules/@tanstack/react-start/src/default-entry/server.ts:16:14)
        at async file:///real-world-project/node_modules/@tanstack/start-plugin-core/dist/esm/dev-server-plugin/plugin.js:112:30

    So my issue might be related to #6056.

  2. 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.

  3. Getting this error when saving files.

  4. I do struggle with it from time to time on HMR, seems like clearing circular deps helps

  5. 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.

Sign in to join this conversation.