Dynamic Code Evaluation not allowed in Edge Runtime Next.js Origin: On your device OSI layer 7 · Application Last updated 5 Nov 2026

Next.js: Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime

Code in middleware or an Edge route uses eval/new Function, which the Edge Runtime forbids.

Exact message you may see Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge RuntimeDynamic Code Evaluation not allowed in Edge RuntimeLearn More: https://nextjs.org/docs/messages/middleware-dynamic-code-evaluationmiddleware dynamic code evaluation
Seen on: Next.js Node.js

Meaning

Often a dependency (jsonwebtoken, some validators, template engines) uses new Function. Replace the library with an Edge-compatible one (e.g. jose for JWT), move the logic to a Node.js route, or use export const runtime = 'nodejs' where allowed (middleware Node runtime available in newer versions).

Common causes

  • jsonwebtoken or similar in middleware
  • Library using new Function/eval internally
  • Bundled dependency from SSR code
  • Edge runtime for route handlers
  • Code generation libs

⚡ Quick fix

  1. Use jose instead of jsonwebtoken
  2. Move heavy logic out of middleware
  3. Set export const runtime = "nodejs" on routes that need Node APIs

Detailed fix by platform

Next.js

  1. import { jwtVerify } from "jose"; // works in Edge

How to diagnose

  1. Library — Uses eval?
  2. Runtime — Edge?
  3. Alternative — jose / Node runtime?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: On your device. Errors that are often confused with or caused by this one (click to open):

Conflicting app and page file was found — Next.js: ⨯ Conflicting app and page file was found, please remove the conflicting files to continue: "pages/index.tsx" - "app/page.tsx" (Next.js)Conflicting app and p…Edge Function size limit exceeded — Vercel: The Edge Function "middleware" size is 1.2 MB and your plan size limit is 1 MB. Learn More: https://vercel.link/edge-function-size (Next.js)Edge Function size li…ERR_TOO_MANY_REDIRECTS (Next.js middleware) — Browser: This page isn't working — redirected you too many times (ERR_TOO_MANY_REDIRECTS) with Next.js middleware / trailing slash (Next.js)ERR_TOO_MANY_REDIRECT…Middleware matcher: Capturing groups are not allowed — Next.js: Error: Invalid middleware found. Capturing groups are not allowed in matcher / `matcher` values must start with `/` (Next.js)Middleware matcher: C…next build: fetch failed ECONNREFUSED (build-time API) — Next.js: Error occurred prerendering page "/blog" TypeError: fetch failed { cause: Error: connect ECONNREFUSED 127.0.0.1:3000 } (Next.js)next build: fetch fai…next build: JavaScript heap out of memory — Next.js: FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory (during next build) (Next.js)next build: JavaScrip…The edge runtime does not support Node.js module — Next.js: The edge runtime does not support Node.js 'crypto' module / A Node.js module is loaded ('fs') which is not supported in the Edge Runtime (Next.js)The edge runtime does…Dynamic C…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.