Help Needed: `UnhandledSchemeError: cloudflare:sockets` with Drizzle ORM and `runtime = "edge"`

Hi Drizzle community, I'm running into a problem while trying to deploy my Next.js API routes using Drizzle ORM with PostgreSQL. Everything works fine locally, but when I set export const runtime = "edge";, I encounter the following error during compilation:
⨯ cloudflare:sockets
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
./src/db/index.ts
./src/app/api/[[...route]]/routes/register/index.ts
./src/app/api/[[...route]]/routes/index.ts
./src/app/api/[[...route]]/route.ts
⨯ cloudflare:sockets
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
./src/db/index.ts
./src/app/api/[[...route]]/routes/register/index.ts
./src/app/api/[[...route]]/routes/index.ts
./src/app/api/[[...route]]/route.ts
My Setup: - Framework: Next.js - Database: PostgreSQL - ORM: Drizzle ORM with postgres package - Runtime: edge (Cloudflare Workers) - Key Code Snippet:
import { env } from "@/config/env";
import { drizzle } from "drizzle-orm/postgres-js";
import postgres from "postgres";

import * as schema from "./schema";

const client = postgres(env.DATABASE_URL);
export const db = drizzle(client, { schema, logger: true });

import { env } from "@/config/env";
import { drizzle } from "drizzle-orm/postgres-js";
import postgres from "postgres";

import * as schema from "./schema";

const client = postgres(env.DATABASE_URL);
export const db = drizzle(client, { schema, logger: true });

Issue Summary: The error seems to stem from the postgres package when trying to use the edge runtime with Cloudflare Workers. It appears that Webpack cannot handle the cloudflare: scheme used in postgres/cf/polyfills.js. Questions: 1. Has anyone else encountered this problem when using Drizzle ORM with Cloudflare Workers and the runtime = "edge" setting? 2. Is there a recommended approach for using Drizzle ORM with PostgreSQL in Cloudflare Workers? Any advice or suggestions would be greatly appreciated! Thanks in advance for your help!
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server