TanStackT
TanStackโ€ข8mo agoโ€ข
4 replies
popular-magenta

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:
import 'dotenv/config';
import { drizzle } from 'drizzle-orm/libsql';

const db = drizzle(process.env.DATABASE_URL!);

export default db;

But in my browser, I am getting an error:
TypeError: args is undefined
    optionMatcher cli-options.js:4
    <anonymous> config.js:6
    <anonymous> config.js:9
...

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 functions
Was this page helpful?