Repository navigation
In progress
In progress
Copy link
Description
Which project does this relate to?
Start
Describe the bug
When a middleware is using a server function that's placed in a different file, using said middleware in a different server function will cause the following error:
Server function info not found for [ID]
It's working fine when the server function is defined in the same file as the middleware
Your Example Website or App
Steps to Reproduce the Bug or Issue
- Add server function in a new file (i.e.
./server-fns/get-foo-bar.ts)
import { createServerFn } from "@tanstack/react-start";
export const getFooBar = createServerFn({ method: "GET" }).handler(
async () => {
return { foo: "bar" };
},
);- Use this server function in a middleware that's stored in a separate file (i.e.
./middlewares/foo-bar-middleware)
import { createMiddleware } from "@tanstack/react-start";
import { getFooBar } from "#/server-fns/get-foo-bar";
export const fooBarMiddleware = createMiddleware({ type: "function" }).server(
async ({ next }) => {
const context = await getFooBar();
return next({ context });
},
);- Use the middleware in a server function that's used within a route (i.e.
./routes/index.tsx)
import { createFileRoute } from "@tanstack/react-router";
import { fooBarMiddleware } from "#/middleware/foo-bar-middleware";
import { createServerFn } from "@tanstack/react-start";
const getFooBar = createServerFn({ method: "GET" })
.middleware([fooBarMiddleware])
.handler(async ({ context }) => {
console.log(context);
return context.foo;
});
export const Route = createFileRoute("/broken")({
component: RouteComponent,
loader: async () => {
const foo = await getFooBar();
return { foo };
},
});
function RouteComponent() {
const foo = Route.useLoaderData({
select: (ctx) => ctx.foo,
});
return <h1>{foo}</h1>;
}- Start the development server and visit the route
- See that the page is working as expected
- Build the application
- Start the production server and visit the same page
- See that the page is broken and the following error is shown:
Server function info not found for [ID]
Expected behavior
As a user, I expected that this would work and that no error was thrown. However, this results in an production breaking exception
Screenshots or Videos
Platform
- Router / Start Version: 1.168.22
- OS: Linux
- Browser: Zen (Firefox based)
- Browser Version: 1.19.8b (Firefox 149.0.2) (64-bit)
- Bundler: Vite
- Bundler Version: 8.0.8
Additional context
No response
Reacted by Jan Hejzlar, fwajgner, Lucas Ferreira and HotTotem
Metadata
Metadata
Assignees
Labels
No labels
Activity
John-Hejzlar commentedon Apr 26, 2026
Same error, my last working versions are:
noubase commentedon Apr 30, 2026
Got the same issue, even without using middleware. Just call:
in a loader for any route.
This
testServerFnsimply calls another server function internally, and you’ll get the same error.The most annoying part is that it works fine in development.
noubase commentedon Apr 30, 2026
├── @tanstack/[email protected]
├── @tanstack/[email protected]
├── @tanstack/[email protected]
├── @tanstack/[email protected]
├── @tanstack/[email protected]
├── @tanstack/[email protected]
├── @tanstack/[email protected]
├── @tanstack/[email protected]
├── @tanstack/[email protected]
├── @tanstack/[email protected]
├── @tanstack/[email protected]
noubase commentedon Apr 30, 2026
Further investigation reveals that you should never call one server function from another, even if the documentation suggests otherwise
fix: restore version of Tanstack Start with working serverFns
fix: restore version of Tanstack Start with working serverFns
aJV99 commentedon May 11, 2026
I doubt it since the last comment was two weeks ago but do we know if any fixes are being worked on? I am wondering if I should consider pinning my versions or make long term fixes moving away from server functions calling one another?
schiller-manuel commentedon May 11, 2026
we are working on this yes
aJV99 commentedon May 11, 2026
After some investigation, looks like the same trigger here. The
createServerFndefined in one file, called from a route loader that internally calls anothercreateServerFnfrom a different file. Production-only;vite devis fine.For me the symptom is a silent hang rather than the thrown "Server function info not found". The resolver's dynamic import for the cross-file handler chunk never resolves, so the loader sits forever and the page never renders.
Pinning to the versions @John-Hejzlar mentioned didn't help. What did: downgrading Vite from 8 to 7 (
vite@^7.3.3,@vitejs/plugin-react@^5.2.0). Every@tanstack/react-startI tried hangs on Vite 8 and works on Vite 7, which points at this maybe being Vite-8 regression rather than a TanStack-version one - I'm not fully sure.Node 24, Linux, node-server Nitro preset.
fix(start-plugin-core): include server-only-reachable server function…
tomh4 commentedon Sep 3, 2026
I have this issue as well, calling a serverfunction from the middleware
docs(compiler-test-utils): oracle README after the V-G1 validation
test(start-plugin-core): pin the #7213 middleware caller deterministi…
test(start-plugin-core): no D6 control row depends on the #7213 race
test(start-plugin-core): assert on Vite that a server-only fn is call…
John-Hejzlar commentedon Oct 27, 2026
I reproduced this on @tanstack/[email protected], @tanstack/[email protected], and Vite 8.3.4 in a production Docker build.
What worked for me was moving shared logic out of createServerFn handlers into createServerOnlyFn helpers. Middleware now calls those helpers directly. Where the browser still needs access, I keep a createServerFn wrapper that calls the same helper.
tomh4 commentedon Nov 2, 2026
@schiller-manuel tried on the latest stable version, still having this issue
petervmeijgaard commentedon Nov 2, 2026
@tomh4 please add a 👍🏻 reaction to the original issue if you're still experiencing this issue. This will indicate that more than 3 people are experiencing this and would like to have this fixed 😄
tomh4 commentedon Nov 2, 2026
@petervmeijgaard done! :)