NextJS on Cloudflare Workers
Unanswered
Devon Rex posted this in #help-forum
Devon RexOP
Hey everyone, I’m trying to connect a PostgreSQL database from my Next.js app deployed on Cloudflare Workers. I’ve tried using pg and Prisma, but Im getting this error:
Any tips of running Postgres with Next.js on Workers? Thanks!
Failed to load external module pg-63e85fc611dc39f8: Error: No such module "pg-63e85fc611dc39f8"Any tips of running Postgres with Next.js on Workers? Thanks!
1 Reply
Rottweiler
That error is happening because Cloudflare Workers don’t support Node.js native modules like pg or Prisma in the usual way — Workers run on the V8 runtime, not Node, so those dependencies can’t be loaded directly.
To use Postgres with Next.js on Cloudflare Workers, you’ll need to use a driver that supports edge runtimes, like a WebSocket/HTTP-based client (e.g. Neon’s serverless driver) or switch to an ORM/adapter that supports edge (like Prisma’s Data Proxy or a fetch-based client).
Alternatively, keep your database access in a separate backend/API (Node server) and have your Worker call it over HTTP.
So the core issue isn’t your code — it’s that pg and Prisma (traditional setup) rely on Node APIs that aren’t available in Workers.
To use Postgres with Next.js on Cloudflare Workers, you’ll need to use a driver that supports edge runtimes, like a WebSocket/HTTP-based client (e.g. Neon’s serverless driver) or switch to an ORM/adapter that supports edge (like Prisma’s Data Proxy or a fetch-based client).
Alternatively, keep your database access in a separate backend/API (Node server) and have your Worker call it over HTTP.
So the core issue isn’t your code — it’s that pg and Prisma (traditional setup) rely on Node APIs that aren’t available in Workers.