Node.js API is not supported in the Edge Runtime
A Node.js API is used (process.cwd) which is not supported in the Edge Runtime. Learn more: https://nextjs.org/docs/api-reference/edge-runtime
In short: Code that uses a Node-only API (or a library like Prisma) is running in the Edge Runtime, which doesn't provide those APIs.
Why it happens
Next.js middleware (middleware.ts, or proxy.ts in Next.js 16+) always runs on the Edge Runtime. Route handlers and server code also run on the edge if the file has export const runtime = 'edge'. The Edge Runtime is a limited workerd-like environment: no fs, path.cwd/process.cwd, child_process, and no Node-only packages such as Prisma's query engine. AI tools often add runtime = 'edge' for speed, or import a database client into middleware to 'check the session'.
How to fix it
- Read the error: it names the Node API and the file. If that file is
middleware.tsorproxy.ts, don't import Prisma,fs, or other Node-only libraries there. Keep middleware to redirects, rewrites, and cookie/session refresh. - If it's a route handler or server file, remove
export const runtime = 'edge'(the default on Vercel is Node) or setexport const runtime = 'nodejs'. - Move Node-only work into a Node route handler or a server library imported only from Node code, not from middleware.
- Check the import chain: a helper that imports Prisma will pull it into any file that imports the helper.
- Redeploy and confirm the function runtime in the host's logs or dashboard.
Example
// app/api/items/route.ts
export const runtime = "nodejs"; // not "edge", if you need Prisma or fs
import { prisma } from "@/lib/prisma";
export async function GET() {
const items = await prisma.item.findMany({ take: 20 });
return Response.json(items);
}
fs and process.cwd in middleware to force a Node library onto the Edge Runtime. Move that code to Node instead.Copy-paste fix prompt
I'm getting this error in my app: A Node.js API is used (process.cwd) which is not supported in the Edge Runtime. Learn more: https://nextjs.org/docs/api-reference/edge-runtime [Paste the full error, stack trace, and the file it points to here] Likely cause: Code that uses a Node-only API (or a library like Prisma) is running in the Edge Runtime, which doesn't provide those APIs. Task: Find the file using a Node.js API or a Node-only library in the Edge Runtime. Keep middleware free of those imports, and run route handlers that need them on the Node.js runtime. Don't stub Node APIs to hide the error. Rules: - First explain the root cause in 2 sentences and list the files you'll change. - Make the smallest change that fixes it. Don't refactor unrelated code. - Don't disable security or checks (RLS, auth, signature verification, type checking, CORS allow-all) to make the error disappear. - Never print or hard-code secret keys. - Finish by telling me exactly how to verify the fix.
Common with: Cursor, v0, Claude Code. Last reviewed 2026-11-15.