What this thread does
Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime
A Next.js production build rejects dynamic evaluation pulled into an Edge entry point, sometimes through a dependency you never call directly.
First action — run pnpm next build and follow its import trace to the first file you own before adding an exception.
Evidence status — Next.js documents the restricted APIs and the exception's limits; two historical reports show dependency import chains, but no application fix here has been reproduced.
Not for: the Node crypto unsupported-module error or PostCSS/lint configuration; see nextjs-edge-crypto-tailwind-postcss-eslint-config-errors.
What changed
- Runtime boundary, checked 2026-10-28: official Proxy history records stable Node middleware in Next.js 15.5.0 (checked 2026-10-28) and the rename to Proxy in 16.0.0 (checked 2026-10-28). Proxy defaults to Node and rejects a
runtimeconfig option. This is a compatibility boundary, not a claim that this error began with those releases. - Restriction, checked 2026-10-28: the dynamic-evaluation guide prohibits eval, function construction and dynamic WASM compilation on Edge; its exception does not enable execution there.
How to migrate the failing import
1. Capture the production failure with pnpm next build (official CLI). Record the installed Next.js version and identify whether the trace belongs to middleware, an Edge route, or another entry point. A development page loading successfully is insufficient. 2. Inspect the dependency named at the top of the trace and the first application import below it. Investigate whether the forbidden dependency can be removed from the Edge import graph; no barrel-splitting repair is established for this application. Untested experiment: remove one application import that pulls in the forbidden dependency, rebuild, and test the affected request paths to check both the import graph and required behavior. 3. If the needed operation genuinely executes dynamic evaluation, remove or replace it, or move that operation to a supported Node entry point. For middleware on Next.js 15.5.0 or later in that major (checked 2026-10-28), the versioned middleware reference documents export const config = { runtime: 'nodejs' }; merge with existing matchers. For Proxy, follow its own reference instead of adding this setting. Confirm the deployment adapter supports the chosen runtime. 4. If WASM is the cause, the official error guide shows importing ./square.wasm?module and passing that module to WebAssembly.instantiate(squareWasm) instead of compiling fetched bytes. Adapt only when the bundler supports that import form. 5. unstable_allowDynamic skips selected build checks; use it only for code proved unreachable, because executing that code on Edge still throws. If such code remains after tree-shaking, consider a narrowly scoped glob. The official example names '/lib/utilities.js'; replace it with the actual offending path relative to the application root. Preserve other config fields. A passing build is not proof of runtime safety.
Diagnostic: Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime
The full leading error above is present in Next.js's compiler source. Treat the following import trace as evidence about what entered the bundle, not proof that the forbidden function executes. Check the lockfile and installed source when line numbers differ.
What breaks
Builds can fail even when your entry point contains no eval. If you exempt a reachable call, the build may pass and the request can still throw on Edge. An overly broad exception conceals additional offending imports.
What to test
Rebuild after each import/config change. Exercise each matching request path, redirects, rejected authorization, and the WASM operation if applicable on the intended deployment adapter. Preserve matchers and access checks. Compare response bodies and headers, not just status codes.
Community evidence
- shinyuna's Next.js issue 51401 shows
lodash-esentering middleware through application utilities in a pnpm monorepo; its attempted exception still failed. This establishes the import-chain symptom, not a universal lodash fix. - AlecKriebel's next-on-pages issue 286 reports a build recovery after an exception for
function-bind, following james-elicx's explanation that the code should never execute. That is a historical adapter-specific report, not evidence that all SDK calls are Edge-safe.
Pitfalls
Do not blanket-allow **/*, polyfill eval, disable authorization, or assume ESM packaging makes a dependency Edge-compatible. Do not paste old experimental runtime names into a current project.
A prompt to give your agent
Your training data may predate these runtime changes. Read the linked official error guide, installed-major middleware reference and Proxy runtime reference before editing; do not guess from the page title. Record the installed version and complete production import trace. Identify the forbidden operation and first application import. Propose one minimal change, preserve matchers and authorization, and distinguish removing code from exempting a build check. Report build and request tests separately.
Limits
No build, import rewrite, WASM execution or deployment was tested. Community evidence is historical and does not establish current frequency or success with coding agents. The error guide uses Proxy terminology while the Proxy runtime reference specifies Node; apply the restriction to the actual failing Edge bundle rather than inferring runtime from that wording. Narrow exceptions require application-specific proof of unreachability. Checked 2026-10-28.
Started from a post by @shinyuna, packaged by the editor. Original post