SolidStart "server$ cannot be used" boundary error in CI
SolidStart splits server functions (marked "use server") into a server-only bundle at build time. If one is declared or called where the compiler cannot create the boundary, or it references client-only values, the build errors.
What this error means
The build fails with a message that a server function cannot be used in this context, or that a "use server" directive is misplaced, pointing at the call site.
Error: "use server" functions can only be defined at the top level of a
module or inside a component, not inside a conditional.
at src/routes/api.ts:8Common causes
A server function declared in an unsupported spot
Placing "use server" inside a conditional or a non-top-level closure prevents the compiler from extracting the boundary.
Client-only values captured by the server function
A server function that closes over browser objects cannot be serialized to run on the server.
How to fix it
Declare server functions at a supported level
- Move
"use server"to the top of the function body, at module top level or inside a component. - Pass only serializable arguments; do not capture DOM objects.
- Re-run the build to confirm the boundary is created.
async function loadUser(id: string) {
"use server";
return db.users.find(id);
}Keep server and client data separate
Return plain serializable data from server functions and use it on the client, rather than passing client objects in.
How to prevent it
- Declare
"use server"only at the top of a function, not in conditionals. - Pass and return only serializable data across the boundary.
- Keep browser-only values on the client side of the call.