Unable to run drizzle query for supabase

I've tried npm, pnpm and bun to check if was something related to how modules are resolved. Here is my drizzle.ts:
import { drizzle } from 'drizzle-orm/postgres-js'
import postgres from 'postgres'

const connectionString = process.env.DATABASE_URL!

export const client = postgres(connectionString, { prepare: false })
export const db = drizzle(client)
import { drizzle } from 'drizzle-orm/postgres-js'
import postgres from 'postgres'

const connectionString = process.env.DATABASE_URL!

export const client = postgres(connectionString, { prepare: false })
export const db = drizzle(client)
Getting this stack trace:
Module build failed: UnhandledSchemeError: Reading from "cloudflare:sockets" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "cloudflare:" URIs.
Import trace for requested module:
cloudflare:sockets
./node_modules/.pnpm/[email protected]/node_modules/postgres/cf/polyfills.js
./node_modules/.pnpm/[email protected]/node_modules/postgres/cf/src/index.js
./db/drizzle.ts
Module build failed: UnhandledSchemeError: Reading from "cloudflare:sockets" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "cloudflare:" URIs.
Import trace for requested module:
cloudflare:sockets
./node_modules/.pnpm/[email protected]/node_modules/postgres/cf/polyfills.js
./node_modules/.pnpm/[email protected]/node_modules/postgres/cf/src/index.js
./db/drizzle.ts
Below is my package json dependencies.
"dependencies": {
"@hono/zod-validator": "^0.2.1",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-slot": "^1.0.2",
"@tanstack/react-query": "^5.40.0",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"dotenv": "^16.4.5",
"drizzle-orm": "^0.30.10",
"hono": "^4.4.0",
"lucide-react": "^0.378.0",
"next": "14.2.3",
"next-themes": "^0.3.0",
"pg": "^8.11.5",
"postgres": "^3.4.4",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-use": "^17.5.0",
"sonner": "^1.4.41",
"tailwind-merge": "^2.3.0",
"tailwindcss-animate": "^1.0.7",
"zod": "^3.23.8"
}
"dependencies": {
"@hono/zod-validator": "^0.2.1",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-slot": "^1.0.2",
"@tanstack/react-query": "^5.40.0",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"dotenv": "^16.4.5",
"drizzle-orm": "^0.30.10",
"hono": "^4.4.0",
"lucide-react": "^0.378.0",
"next": "14.2.3",
"next-themes": "^0.3.0",
"pg": "^8.11.5",
"postgres": "^3.4.4",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-use": "^17.5.0",
"sonner": "^1.4.41",
"tailwind-merge": "^2.3.0",
"tailwindcss-animate": "^1.0.7",
"zod": "^3.23.8"
}
I searched online and found it was happenning for pg 8.11 and tried to manually set it to 8.10 like below and running pnpm up but to no avail:
"pg": "8.10.0",
"pg": "8.10.0",
Any help is much appreciated.
13 Replies
Mykhailo
Mykhailo7mo ago
Hey @Servesh! Do you use Supabase Functions?
Servesh
ServeshOP7mo ago
Not aware of those, first time using Supabase..
Servesh
ServeshOP7mo ago
Here is screenshot from my supabase dashboard
No description
Servesh
ServeshOP7mo ago
No description
Mykhailo
Mykhailo7mo ago
when do you get your error? And I think you should use only postgres driver, so pg driver can be deleted
Servesh
ServeshOP7mo ago
So I'm creating a next js app with app router and I've created an api endpoint. On calling the endpoint from browser or thunder client I get the error
No description
Mykhailo
Mykhailo7mo ago
Try to use neon driver instead of postgres driver https://www.npmjs.com/package/@neondatabase/serverless
import { Pool } from '@neondatabase/serverless';
import { drizzle } from 'drizzle-orm/neon-serverless';

const connectionString = process.env.DATABASE_URL!
const pool = new Pool({ connectionString });
export const db = drizzle(pool)
import { Pool } from '@neondatabase/serverless';
import { drizzle } from 'drizzle-orm/neon-serverless';

const connectionString = process.env.DATABASE_URL!
const pool = new Pool({ connectionString });
export const db = drizzle(pool)
npm
@neondatabase/serverless
node-postgres for serverless environments from neon.tech. Latest version: 0.9.3, last published: 20 days ago. Start using @neondatabase/serverless in your project by running npm i @neondatabase/serverless. There are 17 other projects in the npm registry using @neondatabase/serverless.
Servesh
ServeshOP7mo ago
This totally worked. Thank u so much @Mykhailo . Wow, the config was hard. Can you please tell how did u know to use this driver
Mykhailo
Mykhailo7mo ago
Super! This is due to runtime where you execute your code, postgres-js driver is not available in all runtimes. Do you use cloudflare workers or vercel edge functions?
Servesh
ServeshOP7mo ago
Not as I know of, just created a project in supabase and was playing with the setup. How can I check that? Can u share me your github username so I can give u a shoutout
Mykhailo
Mykhailo7mo ago
Seems like it is due to hono.js or next.js. I will investigate and return to you with more detailed explanation:) github - realmikesolo
Servesh
ServeshOP7mo ago
Yeah Next.js seems to be the cause. I missed the earlier reply to the supabase query of this discussion https://github.com/vercel/next.js/discussions/50177
GitHub
cloudflare plugin · vercel next.js · Discussion #50177
Summary Hi, I am a new developer trying to create a tool to visualize sql data tables, and to render and visualize the tables, I need a PostgreSQL URI so that i can connect to that database, but i ...
Servesh
ServeshOP7mo ago
The reply I referred to uses @vercel/postgres . Do u know if anything that needs to be taken care of
Want results from more Discord servers?
Add your server