nextauthjs / nextauthjs/next-auth

Edge Runtime fails with Magic Link (Email) + MongoDB + Nodemailer setup due to Node.js 'dns' module — not mentioned in docs

Open
#12,979 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

adapters bug triage
Dominant language
TypeScript
Stars
28.4k
Forks
4k
PR merge metrics
No merged PRs in 30d

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:

  1. Explicitly state that using MongoDB + Nodemailer requires the Node.js runtime, not Edge

  2. Offer guidance on how to opt out of Edge runtime, for example by adding export const runtime = 'nodejs' in auth.ts

  3. Optionally suggest alternative edge-compatible configurations or warn about limitations with common adapters

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the auth.ts handler at app/api/auth/[...nextauth]/route.ts and reproduce the failure by building or accessing the auth route. Update the relevant documentation to explain the Node.js runtime requirement for MongoDB and Nodemailer setups, show the runtime opt-out guidance, and note any edge-compatible limitations.

Written by the indexing model from the issue text.

Assessment

Tech stack
mongodb, nextjs, node.js, typescript
Domain
authentication, backend, documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.