I’m getting this warning during next build:
./node_modules/@auth0/nextjs-auth0/dist/utils/dpopUtils.js
A Node.js module is loaded ('crypto' at line 1) which is not supported in the Edge Runtime.
Learn More: https://nextjs.org/docs/messages/node-module-in-edge-runtime
Import trace for requested module:
./node_modules/@auth0/nextjs-auth0/dist/utils/dpopUtils.js
./node_modules/@auth0/nextjs-auth0/dist/server/client.js
./node_modules/@auth0/nextjs-auth0/dist/server/index.js
./lib/auth0.ts
Setup:
-
“next”: “15.3.8” -
“@auth0/nextjs-auth0”: “^4.14.0”
My middleware.ts file:
import type { NextRequest } from "next/server";
import { auth0 } from "./lib/auth0"; // Adjust path if your auth0 client is elsewhere
export async function middleware(request: NextRequest) {
return await auth0.middleware(request);
}
export const config = {
matcher: [
/*
* Match all request paths except for:
* - _next/static (static files)
* - _next/image (image optimization files)
* - favicon.ico, sitemap.xml, robots.txt (metadata files)
*/
"/((?!_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt).*)"
]
};
This is the recommended pattern from the docs.
But during build, my guess is Auth0 internally pulls in Node’s crypto, which Edge doesn’t support.
This started only after upgrading from Auth0 v3 to v4.
v4 introduced using Auth0 in middleware.ts, which runs on the Edge Runtime.
Edge Runtime doesn’t support Node crypto, so Next warns — even though:
-
next devworks -
next build && next startworks -
App behavior is correct at runtime
So:
-
Is
@auth0/nextjs-auth0v4 actually Edge-safe? -
Or is this a known limitation where middleware works but still bundles Node-only code?
-
Is there a recommended way to avoid this warning when using Auth0 in middleware?