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

**Code:** `Dynamic Code Evaluation not allowed in Edge Runtime` · **Category:** Next.js · **Seen on:** Next.js, Node.js

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

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/nextjs/edge-runtime-dynamic-code-evaluation)
