nextauthjs/next-auth · error · ReferenceError

"next-auth/next" is deprecated. If you are not ready to migr

Error message

"next-auth/next" is deprecated. If you are not ready to migrate, keep using "next-auth@4".
Read more on https://authjs.dev/getting-started/migrating-to-v5

What it means

This error is thrown unconditionally when importing the 'next-auth/next' entry point in next-auth v5 (Auth.js). The module no longer exports getServerSession and friends; it exists only to tell developers the API moved to 'next-auth' core exports (auth, signIn, signOut). The library intentionally throws a ReferenceError at module load rather than silently behaving differently.

Source

Thrown at packages/next-auth/src/next.ts:9

/**
 * :::warning Deprecated
 * This module is replaced in v5. Read more at: https://authjs.dev/getting-started/migrating-to-v5#authenticating-server-side
 * :::
 *
 * @module next
 */

throw new ReferenceError(
  [
    '"next-auth/next" is deprecated. If you are not ready to migrate, keep using "next-auth@4".',
    "Read more on https://authjs.dev/getting-started/migrating-to-v5",
  ].join("\n")
)

export {}

View on GitHub (pinned to a1a16a5a77)

Solutions

  1. Replace imports from "next-auth/next" with the root "next-auth" package, e.g. `import { auth } from "next-auth"` or `import { signIn, signOut } from "next-auth"`
  2. Use `auth()` from "next-auth" inside server components/route handlers where you previously used getServerSession
  3. Pin to next-auth@4 if you cannot migrate yet: `npm i next-auth@4`
  4. Follow the official migration guide at https://authjs.dev/getting-started/migrating-to-v5

Example fix

// before
import { getServerSession } from "next-auth/next"
const session = await getServerSession(authOptions)
// after
import { auth } from "next-auth"
const session = await auth()
Defensive patterns

Strategy: validation

Validate before calling

// Fail fast with a clear message if the deprecated entry point is (transitively) imported
const deadEntry = process.env.NEXT_RUNTIME !== undefined
if (process.env.NODE_ENV !== "production" && typeof require === "function") {
  // ensure no module references next-auth/next
  // e.g. grep in CI: ! grep -r "next-auth/next" src/
}

Type guard

function isNextAuthNextImport(imp: string): boolean {
  return imp === "next-auth/next" || imp.startsWith("next-auth/next/")
}

Try / catch

try {
  const mod = await import("next-auth/next")
} catch (e) {
  // ReferenceError: entry point removed in v5
  const { auth } = await import("next-auth")
}

Prevention

When it happens

Trigger: Importing anything from "next-auth/next" (e.g. `import { getServerSession } from "next-auth/next"`) after upgrading to next-auth v5; the module's top-level throw fires as soon as the module is evaluated.

Common situations: Upgrading next-auth@4 to v5 (Auth.js) without updating imports; following old tutorials or Stack Overflow answers that use next-auth/next; partial migration where app router code still references the legacy entry point.

Related errors


AI-assisted analysis of nextauthjs/next-auth@a1a16a5a77 (2026-08-28). Data as JSON: /api/errors/987305062bb4b6b8. Report an issue: GitHub.