Prisma ESM / tRPC 11 issue
Hi everyone!
Key components of our stack:
- Prisma 6.9.0 (with pg adapter)
- Next.js 15.3.3
- tRPC 11.3
- Tanstack React Query 5.80.6
We also use Bun
When attempting to migrate to Prisma ESM client using driverAdapters (as described in the documentation), build errors occur:
The same error occurs for
fs, tls and so on
Using webpack directives in next.config.mjs doesn't solve the problem
As you can see, the stack trace points to the first tRPC call in the client component.
The project uses standard tRPC 11 configuration for Next.js App Router. For testing purposes, I simplified the tRPC context by removing Clerk authentication and keeping only db
Perhaps someone has encountered a similar issue and can suggest a solution. Unfortunately, using the serverless pg driver is not an option for us - we are tightly coupled to Azure.
Thanks4 Replies
You chose to compile with the bot. One moment while I piece together your answer…
Your issue is caused by the fact that the standard Node.js pg driver (used via @prisma/adapter-pg) is not compatible with the Edge Runtime or browser-like environments, such as when code is bundled for the client or for middleware in Next.js. The error about missing modules like dns, fs, and tls is a direct result of the pg driver trying to import Node.js core modules that are not available in these runtimes.
This is a well-documented limitation: the pg driver cannot work in the Edge Runtime because it requires TCP sockets and Node.js modules, which are not supported in environments like Vercel Edge, Next.js middleware, or the browser. This is not a Prisma bug, but a fundamental limitation of the environment and the driver itself. Even locally, you will encounter this issue if your code is executed in an Edge context or is bundled for the client, as the stack trace suggests is happening in your case. See the discussion and error details here: Can't use Prisma Client in Next.js middleware with @prisma/adapter-pg and pg, even locally.
Key points:
- The pg driver (and thus @prisma/adapter-pg) only works in Node.js server environments, not in Edge or browser contexts.
- You cannot use the pg adapter in client components or middleware, nor in any code that is bundled for the browser.
- Workarounds like webpack directives do not solve the fundamental incompatibility.
Alternatives:
If you must run Prisma in an Edge or browser-like environment, you need to use a driver adapter that supports HTTP-based connections, such as Neon, PlanetScale, or Turso. Unfortunately, if you are tightly coupled to Azure and require the standard pg driver, there is currently no supported way to use Prisma in the Edge runtime or in client components for your use case. This limitation is unlikely to change soon source. Summary:
You must ensure all Prism a/pg code runs only in Node.js server environments (API routes, server actions, etc.), not in client components or Edge middleware. There is no supported workaround for using the pg adapter in Edge or browser contexts. 🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly. In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.
If you must run Prisma in an Edge or browser-like environment, you need to use a driver adapter that supports HTTP-based connections, such as Neon, PlanetScale, or Turso. Unfortunately, if you are tightly coupled to Azure and require the standard pg driver, there is currently no supported way to use Prisma in the Edge runtime or in client components for your use case. This limitation is unlikely to change soon source. Summary:
You must ensure all Prism a/pg code runs only in Node.js server environments (API routes, server actions, etc.), not in client components or Edge middleware. There is no supported workaround for using the pg adapter in Edge or browser contexts. 🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly. In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.
Hey!
Is your project open source?
If yes, can you share the link?
A minimal reproduction will be very helpful in investigating this issue.
Hi!
Unfortunately, this is a commercial product. But I can create a reproducible example and share it
Thanks
That would be very helpful 🙏