Next.jsDeployVercel

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

  1. Read the error: it names the Node API and the file. If that file is middleware.ts or proxy.ts, don't import Prisma, fs, or other Node-only libraries there. Keep middleware to redirects, rewrites, and cookie/session refresh.
  2. If it's a route handler or server file, remove export const runtime = 'edge' (the default on Vercel is Node) or set export const runtime = 'nodejs'.
  3. Move Node-only work into a Node route handler or a server library imported only from Node code, not from middleware.
  4. Check the import chain: a helper that imports Prisma will pull it into any file that imports the helper.
  5. 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);
}
Don't: Don't polyfill or mock 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

3 · The fix promptPaste into Cursor, Claude Code, Codex, Lovable, Bolt, Replit or v0
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.

Related fixes

← All fixes · Still stuck? Use the diagnose-first prompt