Error: Client-only API called on the server side
Hi, I want to add a router to my app and I did it as described on https://docs.solidjs.com/solid-start/building-your-application/routing#creating-new-routes.
I'm getting this error:
Did I do it wrong? Shouldn't the file based router part be server side rendered? I'm not sure, coming from Next.js that seems logical ๐
Routing - SolidDocs
Documentation for SolidJS, the signals-powered UI framework
3 Replies
This is what it looks like when you start with the
basic
template:
https://github.com/solidjs/solid-start/blob/main/examples/basic/src/app.tsx
Typically that error message happens when there is server code in a module that is accessed from the client and the bundler can't treeshake the server code out of the client bundle.
In that case moving the supporting server code into a separate bundle usually fixes the problem.
For example: module accessed by the client side:
https://github.com/peerreynders/strello-lab/blob/0d0f9022f5707e93e70a7e78e28c9de1a7146f90/src/server/api.ts
but anything that is referenced to support code under "use server"
is strictly imported making it easy for the bundler to eliminate the server code after the "use server"
sections have been replaced with RPC calls to the server.GitHub
solid-start/examples/basic/src/app.tsx at main ยท solidjs/solid-start
SolidStart, the Solid app framework. Contribute to solidjs/solid-start development by creating an account on GitHub.
GitHub
strello-lab/src/server/api.ts at 0d0f9022f5707e93e70a7e78e28c9de1a7...
Dissecting the Strello SolidStart demo and putting is back together again - peerreynders/strello-lab
Shouldn't the file based router part be server side rendered?SolidStart apps are SPA's with benefits: - SSR on first load - RPC access to the server via
"use server"
The file based router is just a way of configuring things.
- Server routes for first load.
- Client routes for the client side router which does all work after first load.Thanks I'll follow the example code