-
Notifications
You must be signed in to change notification settings - Fork 4k
Description
Adapter type
@auth/mongodb-adapter
Environment
System:
OS: macOS 14.4.1
CPU: (8) Apple M1
Binaries:
Node: 20.11.1
npm: 10.2.3
Yarn: 1.22.19
pnpm: Not Installed
Browser: Chrome 124, Safari 17
npmPackages:
next: 14.1.0
react: 18.2.0
next-auth: 4.24.5
@auth/mongodb-adapter: 1.1.1
Reproduction URL
https://github.com/Nexus-Agni/Project-X/tree/main/apps/web
Describe the issue
I have followed the official AuthJS documentation to implement Magic Link (Email-based) authentication in my Next.js 14 App Router project. The setup uses:
@auth/mongodb-adapter for MongoDB
Nodemailer for email delivery
auth.ts route handler in app/api/auth/[...nextauth]/route.ts
However, upon building the app (or visiting an auth route), the following error is thrown:
Error: The edge runtime does not support Node.js 'dns' module.
Learn More: https://nextjs.org/docs/messages/node-module-in-edge-runtime
This is because the Edge Runtime doesn't support Node.js core modules like dns, but dependencies like mongodb and nodemailer rely on it.
This limitation is not mentioned in the official docs. The auth.ts handler is edge-by-default in Next.js App Router, so most developers following the docs will encounter this error without knowing why.
How to reproduce
Create a new Next.js 14 project using the App Router
Implement Auth.js with magic link email login using:
- @auth/mongodb-adapter for MongoDB
- Nodemailer as the email transport
- Place the auth.ts handler in app/api/auth/[...nextauth]/route.ts
- Attempt to build the project or access the login API route
- You will get the error related to the unsupported dns module in the Edge runtime.
Expected behavior
The documentation should:
-
Explicitly state that using MongoDB + Nodemailer requires the Node.js runtime, not Edge
-
Offer guidance on how to opt out of Edge runtime, for example by adding export const runtime = 'nodejs' in auth.ts
-
Optionally suggest alternative edge-compatible configurations or warn about limitations with common adapters