T
TanStack2mo ago
funny-blue

Where is staticFunctionMiddleware

I am trying to follow Static Server Functions, however i can't as staticFunctionMiddleware cannot be found anywhere. Is there any smart import to do? Or other library to install? Or some module augmentation?
10 Replies
inland-turquoise
inland-turquoise2mo ago
What version are you in? The docs are for 1.132.*
funny-blue
funny-blueOP2mo ago
i have those versions installed
"@tanstack/react-devtools": "^0.2.2",
"@tanstack/react-query": "^5.90.2",
"@tanstack/react-router": "^1.132.0",
"@tanstack/react-router-devtools": "^1.132.0",
"@tanstack/react-router-ssr-query": "^1.131.7",
"@tanstack/react-start": "^1.132.0",
"@tanstack/router-plugin": "^1.132.0",
"@tanstack/react-devtools": "^0.2.2",
"@tanstack/react-query": "^5.90.2",
"@tanstack/react-router": "^1.132.0",
"@tanstack/react-router-devtools": "^1.132.0",
"@tanstack/react-router-ssr-query": "^1.131.7",
"@tanstack/react-start": "^1.132.0",
"@tanstack/router-plugin": "^1.132.0",
inland-turquoise
inland-turquoise2mo ago
I think You must install the package first, @tanstack/start-static-server-functions
funny-blue
funny-blueOP2mo ago
right, it was there in the import... But now i am getting strange issue on line .middleware([staticFunctionMiddleware]) which is
Type 'FunctionMiddlewareAfterServer<{}, unknown, undefined, undefined, undefined, undefined, undefined>' is not assignable to type 'AnyRequestMiddleware | AnyFunctionMiddleware | AnyServerFn'.
Property '[TSS_SERVER_FUNCTION_FACTORY]' is missing in type 'FunctionMiddlewareAfterServer<{}, unknown, undefined, undefined, undefined, undefined, undefined>' but required in type 'ServerFnWithTypes<any, any, any, any, any>'.
Type 'FunctionMiddlewareAfterServer<{}, unknown, undefined, undefined, undefined, undefined, undefined>' is not assignable to type 'AnyRequestMiddleware | AnyFunctionMiddleware | AnyServerFn'.
Property '[TSS_SERVER_FUNCTION_FACTORY]' is missing in type 'FunctionMiddlewareAfterServer<{}, unknown, undefined, undefined, undefined, undefined, undefined>' but required in type 'ServerFnWithTypes<any, any, any, any, any>'.
and when trying to ignore the error and run it anyway i get error in browser's console
import_node_async_hooks.AsyncLocalStorage is not a constructor
at @tanstack_start-static-server-functions.js?t=1759421434724&v=cb209fed:1096:20

The above error occurred in the <Lazy> component.

React will try to recreate this component tree from scratch using the error boundary you provided, CatchBoundaryImpl.
import_node_async_hooks.AsyncLocalStorage is not a constructor
at @tanstack_start-static-server-functions.js?t=1759421434724&v=cb209fed:1096:20

The above error occurred in the <Lazy> component.

React will try to recreate this component tree from scratch using the error boundary you provided, CatchBoundaryImpl.
fair-rose
fair-rose2mo ago
before we go any deeper, what is it that you want to do with that middleware? i am asking because the use case is rather niche
funny-blue
funny-blueOP2mo ago
right, i just want to see how it works. I want to verify two things - how it looks after build, so i want to inspect what was produced in bundles - how it looks in the app and how it works (it will be obvious exercise, i just want eample of simple () => "Hello world" as a static server function) And said "use case is niche", what is the use case then?
fair-rose
fair-rose2mo ago
it allows you to produce sites that are fully static (no backend JS) but still load server side content from the client
funny-blue
funny-blueOP2mo ago
hm ok, thanks do you have maybe working example? or can guide what steps to take to produce correct example? thanks for your time and help so far
fair-rose
fair-rose2mo ago
not right now, we will need to set one up can you please create a github issue with a reproducer that exhibits the above problems so we can properly track this
funny-blue
funny-blueOP2mo ago
GitHub
Code snippet regarding staticFunctionMiddleware from docs is not wo...
Which project does this relate to? Start Describe the bug I just followed example from Static Server Functions and the example there import { createServerFn } from &#39;@tanstack/react-start&#39; i...

Did you find this page helpful?