-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
"Failed to load external module node:module" when attempting to use middleware with Prisma and Neon serverless #12881
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
+1 - similar behaviour with Prisma and local Postgres. Followed this guide to setup Prisma: https://www.prisma.io/docs/getting-started/setup-prisma/add-to-existing-project/relational-databases-typescript-postgresql Followed this guide for Auth.js + Prisma configuration: https://authjs.dev/getting-started/adapters/prisma Hope this helps! |
I find it unclear from your message whether you have it working or not. I'm trying to use Neon Serverless, which Prisma's docs say is one of the database drivers which is edge-compatible (and therefore hopefully middleware-compatible). Which driver are you using? |
Apologies for the confusion - to clarify, I am facing the same issue as yourself and I do not have a working fix as yet. |
Running into the same issue but standalone. Not serverless. Prisma Barebones middleware.ts
Stack trace.
|
I got the same issue as you.
I am not using Neon at all but got the same error using basic install process.
|
I am having the same error with a similar stack : The problem has been resolved. follow this guide:
|
@gmsetiawan, I tried using your example code above and I still see the same error. I committed that to a branch of my test repo: https://github.com/tremby/auth-test/tree/gmsetiawan If you'd be so kind, please check that out and let me know what I've missed. |
Try it
Everything running as you want. |
It's working for me now. Thank you. Using both password and google login. |
Same issue here. Using PlanetScale, Turbopack and experimental Node middleware.
|
Same problem here when using Next.JS Prisma and Local PostgreSQL. Disable Turbopack helps but didn't solve the problem. Any workaround? |
I'm using |
OK, I made that change, and it's no longer erroring. It appears to also work without forcing the session stategy to JWT. But if I understand correctly what this is doing, it's not actually connecting to the database at all. In the middleware file you have it passing configuration to NextAuth which doesn't include the database adapter at all. And I think that'll mean that if I'm not using the JWT strategy, then the middleware's purpose, to refresh tokens, isn't going to be achieved. |
Interesting. I just tried this and that does get me past that error. But now it's complaining that it doesn't have the connection string. It seems middleware doesn't load environment variables. If I try to manually load them, whether with Can you tell us how you got around that, please? |
Can confirm that rolling back to @auth/prisma-adapter 2.7.4 resolved my issue (I'm using prisma + postgres) |
For me I rolled back @auth/prisma-adapter for 2.7.4 In next.config.ts And in middleware file
This worked for me Some links that helped me |
This can be resolved by using two different config for middleware and other things because in next js middleware runs on edge runtime which will not support adapters that we use because database are not compatible running on edge so we segregate config in two parts as below and use config that doesn't contain adapter in middleware.
Finally for normal use cases other than middleware
Thank you! |
Downgrading to @auth/prisma-adapter 2.7.2 should solve it. There is an open issue for this, see #12731 |
What worked for me was the downgrade @auth/prisma-adapter to 2.7.4. but I needed to do a lot of changes to turn Prisma able to work with auth middleware with any errors, main was to separate AuthOptions and in this ways:
and
Maybe somethings was specific because I try external credentials and use MongoDB as database. |
This comment has been minimized.
This comment has been minimized.
Downgrading prisma-adapter version to 2.7.4 solves it. |
Environment
Reproduction URL
https://github.com/tremby/auth-test
Describe the issue
I'm trying to get Nextjs, Authjs/next-auth and its middleware, Prisma, and Neon all working together.
I understand that getting databases to work in edge runtimes is tricky, but the docs say that it is supported with various drivers including the Neon serverless one. I'm using Neon, so that sounds OK to me.
The documentation is difficult to follow, since it boots me off to the Prisma site, and also to the Neon site, and each one seems to give slightly different instructions.
I've done my best to follow the instructions. The most straightforward route through the docs which looks to my eye like it ought to be complete is included in the reproduction repo. Step through its commits and see the messages for details. Not included in the reproduction repo, I also tried various different versions and combinations of the instructions, anything I could find.
With every iteration, when running
npm run dev
and navigating tolocalhost:3000
I see a stack trace, and in the console I have a lot of these:How to reproduce
npm install
cp .env.example .env
vim .env
and fill in valuesnpx prisma generate
npm run dev
localhost:3000
Expected behavior
Middleware executes successfully. Page loads. No errors.
The text was updated successfully, but these errors were encountered: