Server side library running on client
Hello, I am a tanstack start begginer. I am trying to switch from Prisma to Drizzle ORMs because I was facing a weird issue with Prisma. My server code requires .env variables, but the client browser is trying to execute the same code, which causes of course an issue.
I am trying to do this:
But in my browser, I am getting an error:
Clicking the
cli-options
link shows that the dotenv library is being executed on the client 😅
I was taking a look at this repo:
https://github.com/aaronksaunders/tanstack-start-drizzle-app/tree/main
He does the same as I do except that his database file path is hardcoded
https://github.com/aaronksaunders/tanstack-start-drizzle-app/blob/e867a96e3e1097018c64b7f9cccf93d34b1b6c9d/drizzle/db.ts#L10C1-L11C17
... So my question would be, how am I supposed to "split" the server side code and the client one in this case? I have to import my db variable to be used in the server functions2 Replies
national-gold•4mo ago
where can you show a complete example?
or is this the repo you linked to?
if you only use
db
inside of server functions, it will be split by start automaticallystuck-chocolateOP•4mo ago
Oh dang... I have realized I was trying to add GraphQL to my project, I am importing and using the db variable in the GraphQL Mutation resolver 😵💫 if I comment out that part the error dissapears ...
I will try to figure out how to use graphql and server functions properly ...