solid-start
solid-start copied to clipboard
server$ can't be exported as default
Using server$ as default export breaks build.
export default server$(async (path: string) => {
// Do stuff
});
Produces:
An error occured while server rendering /program/33740:
Error: Should be compiled away
at Module.server$ [as default] (/Users/jchatard/Documents/XXXX/XXXX.fr/front-solidjs/node_modules/.pnpm/[email protected]_hbwrjiud3j45e6mxm6q434ty3e/node_modules/solid-start/server/server-functions/server.ts:21:8)
at /Users/jchatard/Documents/XXXX/XXXX.fr/front-solidjs/src/lib/fetcher.ts:14:23
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async instantiateModule (file:///Users/jchatard/Documents/XXXX/XXXX.fr/front-solidjs/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-51c4f80a.js:53053:9
But this works:
export const fetchAPI = () => server$(async (path: string) => {
// Do stuff
});
Works!
And here's a repro: https://github.com/jchatard/should_be_compiled_away
To give an update, I have been struggling to make it work in my full app, until I stumbled accross this comment from @nksaraf on Discord:
Yeah this is very fair... since its only me who has worked on it and used it extensively.. subconciously I know what to do.. one thing to look out for it to make sure the files are .tsx when you use server functions since that can cause the compiled error thing
So renaming files which contained server$calls from *.ts to *.tsx, solved my issue.