prevent db module going to client
I'm trying to execute a db query on my route loader, but my db file imports "server-only" and I'm getting this error
this is my route:
how can I prevent my db module from going to the client
8 Replies
unwilling-turquoise•2w ago
Use createServerFn for the query and call the function from your loader
grumpy-cyanOP•2w ago
still having the same issue. is this right?
unwilling-turquoise•2w ago
That looks right. Are you doing this multiple places? Try restarting dev server also
grumpy-cyanOP•2w ago
no, this is the only route I have. just setup the project.
this is my db file
issue persists after restarting the dev server
am I missing something?
rival-black•2w ago
the problem is "server-only"
dont import it
this is not supported
grumpy-cyanOP•2w ago
ohh okay, it works now!
I'm using it because I didn't had the db in a server function before, so drizzle was getting some missing modules since it was running on the client
shouldn't all code inside "loader" be exclusive to the server since it only runs there?
rival-black•2w ago
no
loaders are isomorphic, that means they run on the server for the SSR request and then on the client for each subsequent navigations
grumpy-cyanOP•2w ago
oh okay, it makes sense!
thanks!