How do I use Drizzle both locally in node and deployed on Vercel Edge?

I'm having some trouble with Drizzle + Postgres, deployed to Vercel. I can either get it working when deployed to vercel edge with my db connector like:
const connectionString = this.env.get("DATABASE_URL") as string;
const pool = new Pool({ connectionString });
const db = drizzle(pool);
const connectionString = this.env.get("DATABASE_URL") as string;
const pool = new Pool({ connectionString });
const db = drizzle(pool);
But then it doesn't work locally in dev, with the following error:
Uncaught (in promise) Error: All attempts to open a WebSocket to connect to the database failed. Please refer to https://github.com/neondatabase/serverless#run-on-node
Uncaught (in promise) Error: All attempts to open a WebSocket to connect to the database failed. Please refer to https://github.com/neondatabase/serverless#run-on-node
(I tried following the instructions there doesn't seem to resolve the issue, and just introduces node dependencies into my app, which then can't run on Vercel Edge). If I instead just set it up with
const client = postgres(connectionString);
const db = drizzle(client);
const client = postgres(connectionString);
const db = drizzle(client);
Then it works locally in dev, but fails to build (with the same issue of node dependencies can't be deployed to Vercel Edge). This is all in the context of a Qwik app (but I don't think this detail impacts the issue). How can I resolve this issue so that it works both locally in node dev and also deployed to Vercel Edge?
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server