"use server" confusion
i have this action in a
src/routes/tables.tsx file.
the schedule function just inserts a new row into sqlite. this will work just fine in this file where the component that has the <form> which consumes it lives. however, if i move this to eg src/server/tables/actions.ts like:
and import the file from there, vite complains Module "fs" has been externalized for browser compatibility. Cannot access "fs.access" in client code. etc and my app does not work as expected (doesn't react to clicks).
So I'm wondering how does "use server" exactly work and what are the caveats? why does it not behave as expected in my case?2 Replies
the action itself can’t be used with toplevel "use server" as it needs to run on the client.
Only the function wrapped by action/query can be "use server".
thank you for clarifying