Skip to content

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

@ulrichstark

Description

@ulrichstark

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.

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