TypeError: action is not a function #6056
Send to my agentWhich project does this relate to?#
Start
Describe the bug#
Occasionally im getting TypeError: action is not a function when calling a server function from the client.
TypeError: action is not a function at /Users/jclackett/Apps/Noa/cf/node_modules/@tanstack/start-server-core/src/server-functions-handler.ts:135:24 at eval (/Users/jclackett/Apps/Noa/cf/node_modules/@tanstack/start-server-core/dist/esm/server-functions-handler.js:80:6) at handleServerAction (/Users/jclackett/Apps/Noa/cf/node_modules/@tanstack/start-server-core/dist/esm/server-functions-handler.js:173:4) at /Users/jclackett/Apps/Noa/cf/node_modules/@tanstack/start-server-core/src/createStartHandler.ts:156:26 at /Users/jclackett/Apps/Noa/cf/node_modules/@tanstack/start-server-core/src/createStartHandler.ts:145:28 at /Users/jclackett/Apps/Noa/cf/node_modules/@tanstack/start-server-core/src/createStartHandler.ts:439:22 at next (/Users/jclackett/Apps/Noa/cf/node_modules/@tanstack/start-server-core/src/createStartHandler.ts:457:16) at startRequestResolver (/Users/jclackett/Apps/Noa/cf/node_modules/@tanstack/start-server-core/src/createStartHandler.ts:248:19) at fetch (/Users/jclackett/Apps/Noa/cf/node_modules/@tanstack/react-start/dist/plugin/default-entry/server.ts:16:14) at EnvRunner.fetch (file:///Users/jclackett/Apps/Noa/cf/node_modules/nitro/dist/runtime/internal/vite/dev-worker.mjs:78:14) Server Fn Error!
Your Example Website or App#
Steps to Reproduce the Bug or Issue#
I'm doing my best to create a repro, but it's proving tricky - will continue to work on that but I think its worth tracking this issue anyway as I've seen a few discussions with the same error.
My current setup, and when it fails, is intercepting 401 errors and then calling a server function to refresh the token and replay the original request. Sometimes when this happens the server function fails with the error stated above.
Im using tanstack query on the client, and im wondering if it has something to do with race conditions. it happens when I come back to an inactive tab and tanstack refetches all the stale queries. if the main access token has expired and needs refreshing it tries to call the server function many times and thats causing some error?
Expected behavior#
Server functions dont throw TypeError: action is not a function
Screenshots or Videos#
No response
Platform#
- Router / Start Version: latest
- OS: macOS
- Browser: Chrome
- Browser Version: latest
- Bundler: vite
- Bundler Version: v8 beta
Additional context#
please add a complete reproducer project as a git repo
schiller-manuel(GitHub profile, opens in a new tab) added labelsinformation needed
yeah working on it!
@Pyakz can you please provide a complete reproducer project?
@JClackett were you able to come up with a reproducer based on latest start version?
I have a project that's causing the same issue.
I've stripped a lot of the functionality from another repo and made a new one. I occasionally notice the error going off from random server events, but to guarantee it, just HMR the server.ts file.
having it on two different Start projects. It happens randomly on HMR. Just saving a file to re-trigger HMR usually fixes the issue.
I have this same issue as well and sometimes it crashes the dev server completely with this error:
Error in renderToPipeableStream: TypeError: serverFn is not a functionedit: only during HMR, only when saving the serverFn file itself, not when saving the consuming components files.
Noticed that if we were to await and ensureQuery, the error will not be caught be a error boundary - however it will still appear on the console.
I didn't have time to fully test, but the issue goes away for me when downgrading to the previous version we had in our project,
1.139.1. This is of course not a fix, but at least it's a tell that it was introduced in a new version and not specifically in our code.edit: I downgraded all tanstack packages to that version, will try to find time next week to pin point it.
Seems like an issue of newer tanstack releases, thanks @murm , donwgrading to 1.139.1 helps me too. The issue is exactly the same — when starting dev server, it crashes with
serverFn is not a function, editing any file withcreateServerFnhelps after HMR, seems like a bundling issue :)My issue #6451 is about the crash with the error
serverFn is not a functionand might be related to this issue because in my original project, where my reproduction project comes from, I'm also seeingTypeError: action is not a functionunder the same circumstances.Same.
I am seeing the same problem; it is manifesting as an occasional flakiness in my e2e tests, causing my test suite to fail. So far, just rerunning once, then all tests pass. I do not have a repro project, but I can at least offer this stack trace:
[WebServer] Server Fn Error! [WebServer] [WebServer] TypeError: action is not a function [WebServer] at eval (.../node_modules/@tanstack/start-server-core/src/server-functions-handler.ts:132:24) [WebServer] at eval (.../node_modules/@tanstack/start-server-core/src/server-functions-handler.ts:148:7) [WebServer] at handleServerAction (.../node_modules/@tanstack/start-server-core/src/server-functions-handler.ts:352:3) [WebServer] at process.processTicksAndRejections (node:internal/process/task_queues:104:5) [WebServer] at async next (.../node_modules/@tanstack/start-server-core/src/createStartHandler.ts:279:16) [WebServer] at async next (.../node_modules/@tanstack/start-server-core/src/createStartHandler.ts:279:16) [WebServer] at async startRequestResolver (.../node_modules/@tanstack/start-server-core/src/createStartHandler.ts:532:21) [WebServer] at async Object.fetch (.../node_modules/@tanstack/react-start/dist/plugin/default-entry/server.ts:16:14) [WebServer] at async file://.../node_modules/@tanstack/start-plugin-core/dist/esm/dev-server-plugin/plugin.js:112:30
Sign in to join this conversation.
📝 CodeRabbit Plan Mode#
Generate an implementation plan and agent prompts for this issue.
Examples
🔗 Related PRs#
TanStack/router#5276 - fix: raw response handling [merged] TanStack/router#5501 - fix: undefined / null serialization [merged] TanStack/router#5513 - fix: no invalidation for server functions in dev [merged] TanStack/router#5650 - fix: fix static server functions [merged] TanStack/router#5935 - fix(start-server-core): deserialize tss context when using formdata [merged]
👤 Suggested Assignees#
🧪 Issue enrichment is currently in early access.
To disable automatic issue enrichment, add the following to your
.coderabbit.yaml: