You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've hit a wall trying to switch the Postgres driver in the create-t3-turbo template from drizzle-orm/vercel-postgres to drizzle-orm/node-postgres. While database migrations are working fine, the app keeps failing during startup and hydration in different Node.js environments. I'm seeing net.Socket errors and Edge runtime issues with the Node.js crypto module. I've tried several workarounds, but nothing's sticking.
Describe the bug
I've run into some frustrating runtime compatibility issues while trying to swap out the Postgres driver in the create-t3-turbo template. Here's what I'm seeing:
On Node v22.12.0, I'm getting hit with net.Socket constructor errors in the Next.js React Server Components (RSC) environment
On Node v20.18.1, I'm running into Edge runtime issues with the Node.js crypto module and missing pg-native dependencies
The weird part? Database operations like schema migrations using drizzle-kit push work perfectly fine. It's just when the app tries to start up that everything falls apart.
I've thrown quite a few potential solutions at this problem:
Removed all "Edge" exports from the project
Tweaked the Webpack config in next.config.js to exclude problematic Node.js modules
Verified that CLI database operations work (they do!)
Even got it working in a closed-source project by suppressing similar errors, but can't replicate that success in a clean setup
Despite all these attempts, the issue keeps showing up during runtime when using the Node.js runtime.
Additional information
Introduction
Hey there! I've been diving deep into the create-t3-turbo template and hit some pretty significant roadblocks while trying to switch database drivers. My goal was to use the node-postgres driver for better compatibility with self-hosted setups, but I'm running into walls with both RSC and Edge runtime environments.
Description
The problems started when I tried switching from drizzle-orm/vercel-postgres to drizzle-orm/node-postgres in the packages/db and packages/api directories. I'm seeing runtime errors related to Node.js native modules like net and crypto. It seems to be tied to Next.js runtime limitations.
Error Messages
Original Repository (Node v22.12.0)
TypeError: net.Socket is not a constructor
at getStream (webpack-internal:///(rsc)/../../node_modules/pg/lib/stream.js:23:12)
at new Connection (webpack-internal:///(rsc)/../../node_modules/pg/lib/connection.js:18:36)
at new Client (webpack-internal:///(rsc)/../../node_modules/pg/lib/client.js:48:7)
Reproduction Repository (Node v20.18.1)
Error: The edge runtime does not support Node.js 'crypto' module.
Learn More: https://nextjs.org/docs/messages/node-module-in-edge-runtime
at <unknown> (webpack-internal:///(middleware)/../../node_modules/next/dist/esm/server/web/globals.js:34)
And just to make things more interesting, I'm also seeing this in the reproduction:
Module not found: Can't resolve 'pg-native' in '/Users/.../node_modules/pg/lib/native'Import trace for requested module:../../node_modules/pg/lib/native/client.js../../node_modules/pg/lib/native/index.js../../node_modules/pg/lib/index.js../../packages/db/src/client.ts../../packages/auth/src/config.ts../../packages/auth/src/index.ts
If you want to join the discussion, I've started a thread in Theo's Typesafe Cult
Additional Context
From what I can tell, these errors are popping up because of how Next.js interacts with Node.js native modules in RSC and Edge runtime environments. This feels more like a fundamental runtime compatibility issue rather than just a configuration problem.
Expected Behavior
In an ideal world, the app should just connect to Postgres using the node-postgres driver without throwing fits about net.Socket, crypto, or pg-native. It should run smoothly on the Node.js runtime like any other normal app.
Questions
I'm still wrestling with these questions:
Is there a "right way" to use node-postgres with Next.js RSC?
Are there known limitations I should be aware of?
How are others handling Node.js native modules in the Edge runtime?
Contributing Back to the Community
Once we crack this, I'd love to give back by:
Writing up a detailed guide on switching from vercel-postgres to node-postgres
Documenting all the configuration changes and workarounds needed
Sharing best practices for using node-postgres in Next.js RSC/Edge environments
Warning others about the pitfalls I've discovered
Thanks in advance for any help or insights you can share! Let's figure this out together.
The text was updated successfully, but these errors were encountered:
We've experienced this in the past and this is because the middleware always is set to "edge" and what was done in the past is to use pg-proxy or some other setup that allows you to use something else this can be worked around if you adjust the auth config also explained here: https://authjs.dev/guides/edge-compatibility#middleware
Provide environment information
TL;DR
I've hit a wall trying to switch the Postgres driver in the
create-t3-turbo
template fromdrizzle-orm/vercel-postgres
todrizzle-orm/node-postgres
. While database migrations are working fine, the app keeps failing during startup and hydration in different Node.js environments. I'm seeingnet.Socket
errors and Edge runtime issues with the Node.jscrypto
module. I've tried several workarounds, but nothing's sticking.Describe the bug
I've run into some frustrating runtime compatibility issues while trying to swap out the Postgres driver in the
create-t3-turbo
template. Here's what I'm seeing:net.Socket
constructor errors in the Next.js React Server Components (RSC) environmentcrypto
module and missingpg-native
dependenciesThe weird part? Database operations like schema migrations using
drizzle-kit push
work perfectly fine. It's just when the app tries to start up that everything falls apart.Link to reproduction
LinnJS/t3-turborepo-node-pg-driver#1
To reproduce
git fetch origin main
git checkout feat/add-pg-driver
pnpm install --filter @acme/nextjs...
pnpm dev --filter @acme/nextjs...
Previous Attempted Workarounds
I've thrown quite a few potential solutions at this problem:
next.config.js
to exclude problematic Node.js modulesDespite all these attempts, the issue keeps showing up during runtime when using the Node.js runtime.
Additional information
Introduction
Hey there! I've been diving deep into the
create-t3-turbo
template and hit some pretty significant roadblocks while trying to switch database drivers. My goal was to use thenode-postgres
driver for better compatibility with self-hosted setups, but I'm running into walls with both RSC and Edge runtime environments.Description
The problems started when I tried switching from
drizzle-orm/vercel-postgres
todrizzle-orm/node-postgres
in thepackages/db
andpackages/api
directories. I'm seeing runtime errors related to Node.js native modules likenet
andcrypto
. It seems to be tied to Next.js runtime limitations.Error Messages
Original Repository (Node v22.12.0)
Reproduction Repository (Node v20.18.1)
And just to make things more interesting, I'm also seeing this in the reproduction:
Reproduction Repository
t3-turborepo-node-pg-driver
Related Discussions
Discord Thread Reference
If you want to join the discussion, I've started a thread in Theo's Typesafe Cult
Additional Context
From what I can tell, these errors are popping up because of how Next.js interacts with Node.js native modules in RSC and Edge runtime environments. This feels more like a fundamental runtime compatibility issue rather than just a configuration problem.
Expected Behavior
In an ideal world, the app should just connect to Postgres using the
node-postgres
driver without throwing fits aboutnet.Socket
,crypto
, orpg-native
. It should run smoothly on the Node.js runtime like any other normal app.Questions
I'm still wrestling with these questions:
node-postgres
with Next.js RSC?Contributing Back to the Community
Once we crack this, I'd love to give back by:
vercel-postgres
tonode-postgres
node-postgres
in Next.js RSC/Edge environmentsThanks in advance for any help or insights you can share! Let's figure this out together.
The text was updated successfully, but these errors were encountered: