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
{{ message }}
Repository navigation
UnhandledSchemeError when using Drizzle ORM with Next.js authentication application #810
Description:
I am encountering an issue while using postgres.js with Drizzle ORM in a Next.js authentication application. Despite not using Cloudflare Workers in my project, I'm encountering an error related to "cloudflare:sockets", indicating an UnhandledSchemeError.
Here's a summary of the relevant code and context:
// auth.tsimportNextAuth,{DefaultSession}from"next-auth";import{authConfig}from"./auth.config";import{DrizzleAdapter}from"@auth/drizzle-adapter";importdbfrom"@/database/db";exportconst{handlers: {GET,POST},
auth,
signIn,
signOut,}=NextAuth({callbacks: {asyncsession({ token, session }){// Session callback logic},asyncjwt({ token }){// JWT callback logic// Issue seems to arise here when interacting with the database},},adapter: DrizzleAdapter(db),secret: process.env.NEXTAUTH_SECRET,session: {strategy: "jwt"},});
// middleware.tsexport{authasdefault}from"./auth"
The error message received is:
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/postgres/cf/polyfills.js
./node_modules/postgres/cf/src/index.js
./src/database/db.ts
./src/auth.ts
Reacted by Javi Aguilar, Kiryl Chetyrbak, Jan Szymański, Abdullah Elsayed, Chenalejandro, shortear, Fernando Goncalves, Claudio Rivera, ToastedToast, Curetix and 10 more
I have a similar problem in my middleware.ts. My error message is:
[auth][error] AdapterError: Read more at [https://errors.authjs.dev#adaptererror](https://errors.authjs.dev/#adaptererror)
[auth][cause]: Error: The edge runtime does not support Node.js 'net' module.
Learn More: https://nextjs.org/docs/messages/node-module-in-edge-runtime
at Object.apply (webpack-internal:///(middleware)/./node_modules/next/dist/esm/server/web/globals.js:43:19)
at createSocket (webpack-internal:///(middleware)/./node_modules/postgres/src/connection.js:146:44)
at Timeout.connect [as _onTimeout] (webpack-internal:///(middleware)/./node_modules/postgres/src/connection.js:343:31)
at listOnTimeout (node:internal/timers:573:17)
at process.processTimers (node:internal/timers:514:7)
[auth][error] SessionTokenError: Read more at [https://errors.authjs.dev#sessiontokenerror](https://errors.authjs.dev/#sessiontokenerror)
[auth][cause]: Error: The edge runtime does not support Node.js 'net' module.
Learn More: https://nextjs.org/docs/messages/node-module-in-edge-runtime
at Object.apply (webpack-internal:///(middleware)/./node_modules/next/dist/esm/server/web/globals.js:43:19)
at createSocket (webpack-internal:///(middleware)/./node_modules/postgres/src/connection.js:146:44)
at Timeout.connect [as _onTimeout] (webpack-internal:///(middleware)/./node_modules/postgres/src/connection.js:343:31)
at listOnTimeout (node:internal/timers:573:17)
at process.processTimers (node:internal/timers:514:7)
Activity
itsjavi commentedon Mar 25, 2024
Same here, tried with both node v18 and v20. I am on latest Next.js 14.1 and Drizzle 0.30.4
I think it's because the
edgeruntime is not supported. I hadexport runtime = 'edge'in one of my routes using the DB. After removing it it worked.middleware.tsis always usingedge.da1z commentedon Apr 12, 2024
same here. i was hoping it supports edge runtime
jckw commentedon Apr 17, 2024
I just contributed to the bounty on this issue.
Each contribution to this bounty has an expiry time and will be auto-refunded to the contributor if the issue is not solved before then.
To make this a public bounty or have a reward split, the maintainer can reply to this comment.
mlntr commentedon May 19, 2024
I have a similar problem in my middleware.ts. My error message is:
Filip4130 commentedon May 22, 2024
Just ran into this issue, found a fix. It's somwhere between 2:05:00 and 2:23:00 in https://www.youtube.com/watch?v=1MTyCvS05V4&list=WL&index=58&t=109s&ab_channel=CodeWithAntonio
knnedy commentedon May 29, 2024
borisyankov commentedon Jul 3, 2024
The solution in the video starts at 2:18:49
https://www.youtube.com/watch?v=1MTyCvS05V4&t=8327s
v4