Error: The edge runtime does not support Node.js 'crypto' module
This error only come up after I added middleware Searched issue on GitHub , no report about it on better-auth (or I am blind) tried to search more info appears that next-auth also have same issue as better-auth
I need help here: How to bypass it or we have to not use middleware until it fixes?
My middleware.ts:
import { NextRequest, NextResponse } from "next/server";import { headers } from "next/headers";import { auth } from "@/utils/auth";export async function middleware(request: NextRequest) { const session = await auth.api.getSession({ headers: await headers(), }); if (!session) { return NextResponse.redirect(new URL("/", request.url)); } return NextResponse.next();}export const config = { runtime: "nodejs", // I make sure this is nodejs matcher: ["/protected"], // Apply middleware to specific routes};
import { NextRequest, NextResponse } from "next/server";import { headers } from "next/headers";import { auth } from "@/utils/auth";export async function middleware(request: NextRequest) { const session = await auth.api.getSession({ headers: await headers(), }); if (!session) { return NextResponse.redirect(new URL("/", request.url)); } return NextResponse.next();}export const config = { runtime: "nodejs", // I make sure this is nodejs matcher: ["/protected"], // Apply middleware to specific routes};
What I did:
1. I create new next js app to try out better auth 2. I follow the installation guide here 3. I install mongo db adapter guide here 4. I copy and modify
middleware.ts
middleware.ts
to work with my directory 5. bug ->This error occurs (the Image)
The error:
The edge runtime does not support Node.js 'crypto' module
The edge runtime does not support Node.js 'crypto' module
node:internal/process/promises:394 triggerUncaughtException(err, true /* fromPromise */); ^[CanaryOnlyError: The experimental feature "experimental.nodeMiddleware" can only be enabled when using the latest canary version of Next.js.]
node:internal/process/promises:394 triggerUncaughtException(err, true /* fromPromise */); ^[CanaryOnlyError: The experimental feature "experimental.nodeMiddleware" can only be enabled when using the latest canary version of Next.js.]