nextauthjs / nextauthjs/next-auth
"Failed to load external module node:module" when attempting to use middleware with Prisma and Neon serverless
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 28.4k
- Forks
- 4k
- PR merge metrics
- No merged PRs in 30d
Description
Environment
System:
OS: Linux 6.8 Ubuntu 22.04.5 LTS 22.04.5 LTS (Jammy Jellyfish)
CPU: (8) x64 Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz
Memory: 22.17 GB / 31.28 GB
Container: Yes
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 20.10.0 - ~/.nvm/versions/node/v20.10.0/bin/node
Yarn: 1.22.22 - ~/.nvm/versions/node/v20.10.0/bin/yarn
npm: 10.2.3 - ~/.nvm/versions/node/v20.10.0/bin/npm
pnpm: 9.7.1 - ~/.nvm/versions/node/v20.10.0/bin/pnpm
Browsers:
Chromium: 135.0.7049.84
npmPackages:
@auth/prisma-adapter: ^2.8.0 => 2.8.0
@neondatabase/serverless: ^1.0.0 => 1.0.0
next: 15.3.0 => 15.3.0
next-auth: ^5.0.0-beta.25 => 5.0.0-beta.25
prisma: ^6.6.0 => 6.6.0
react: ^19.0.0 => 19.1.0
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 to localhost:3000 I see a stack trace, and in the console I have a lot of these:
⨯ [Error: Failed to load external module node:module: ReferenceError: Cannot access 'require' before initialization]
How to reproduce
- Check out the reproduction repo
npm installcp .env.example .envvim .envand fill in valuesnpx prisma generatenpm run dev- Navigate to
localhost:3000 - See stack trace and console output
Expected behavior
Middleware executes successfully. Page loads. No errors.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reproduction repository at https://github.com/tremby/auth-test and review its commit messages for the setup variations. Run the documented npm install, Prisma generation, development server, and localhost steps, then investigate the middleware integration involving Next.js, Auth.js, Prisma, and Neon. Done means the middleware executes, the page loads, and the node:module errors no longer appear.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- nextjs, nodejs, react, typescript
- Domain
- authentication, backend, database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100