Drizzle + Sveltekit + Cloudflare + Supabase cannot get to work.

If I use Drizzle's docs, like :
import { Pool } from "pg";
import { drizzle } from "drizzle-orm/node-postgres";
import { Pool } from "pg";
import { drizzle } from "drizzle-orm/node-postgres";
I get node module resolution errors like:
node_modules/pg/lib/connection-parameters.js:3:18: ERROR: Could not resolve "dns"
node_modules/pg/lib/connection.js:3:18: ERROR: Could not resolve "net"
node_modules/pg/lib/connection-parameters.js:3:18: ERROR: Could not resolve "dns"
node_modules/pg/lib/connection.js:3:18: ERROR: Could not resolve "net"
If I follow Supabase's docs on connecting with drizzle, like:
import { drizzle } from 'drizzle-orm/postgres-js'
import postgres from 'postgres'
import { drizzle } from 'drizzle-orm/postgres-js'
import postgres from 'postgres'
I get node module errors like:
node_modules/postgres/cf/src/connection.js:1:23: ERROR: Could not resolve "node:buffer"
node_modules/postgres/cf/src/connection.js:6:19: ERROR: Could not resolve "node:stream"
node_modules/postgres/cf/src/connection.js:1:23: ERROR: Could not resolve "node:buffer"
node_modules/postgres/cf/src/connection.js:6:19: ERROR: Could not resolve "node:stream"
Cloudflare definitely says to use the newer colon-delimited name like node:stream, and I have followed all of Cloudflare's instructions for node compatibility, but these errors persist. Anyone have advice?
5 Replies
sizzF
sizzF12mo ago
Add the option node_compat = true to wrangler.toml.
Budi
Budi11mo ago
Did you try postgres-js instead of node-postgres for the drizzle import? Worked for me
boggin
bogginOP11mo ago
I tried adding in node_compat=true flag in the dashboard (I dont have a wrnagler file with Sveltekit) I'm not sure if I tried postgres-js (OP was too long ago to remember) I gave up and just started using Supabase's sdk which is certianly enough of an ORM, I was looking to keep the ORM flavor with drizzle. I will try this just for funsies though
Mike Oristian
Mike Oristian8mo ago
having the same problem - tried with both postgres-js and pg library
Shashank
Shashank3mo ago
Serverless Drivers | Supabase Docs
Connecting to your Postgres database in serverless environments.
Want results from more Discord servers?
Add your server