Skip to content

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

@Nexus-Agni

Description

@Nexus-Agni

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    adaptersChanges related to the core code concerning database adaptersbugSomething isn't workingtriageUnseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions