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.
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 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/evalinternally - Bundled dependency from SSR code
- Edge runtime for route handlers
- Code generation libs
⚡ Quick fix
- Use
joseinstead ofjsonwebtoken - Move heavy logic out of middleware
- Set
export const runtime = "nodejs"on routes that need Node APIs
Detailed fix by platform
Next.js
import { jwtVerify } from "jose"; // works in Edge
How to diagnose
- Library — Uses eval?
- Runtime — Edge?
- 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:
Similar errors
- 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"
- 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
- 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
Most viewed in Next.js
- NEXT_REDIRECT Next.js: Error: NEXT_REDIRECT (redirect() inside try/catch)
- server-only Next.js: You're importing a component that needs "server-only". That only works in a Server Component
- cookies() should be awaited Next.js 15: Route "/x" used `cookies().get('token')`. `cookies()` should be awaited before using its value
Other ways to find it
Where this error sits
Origin: On your device. Errors that are often confused with or caused by this one (click to open):
🧠 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.
Report a correction or suggest an improvement
Last updated 5 Nov 2026