- Node.js Runtime (default): full Node.js API surface, used for rendering and route handlers.
- Edge Runtime: a subset of Web APIs, optimized for low-latency responses at the edge. Used in Middleware.
Choosing a runtime
Setting the runtime
Specify the runtime in a Route Handler or layout/page segment using theruntime export:
app/api/route.ts
'edge' or 'nodejs'. When omitted, the Node.js runtime is used.
ISR (Incremental Static Regeneration) is not supported in the Edge Runtime.
Supported APIs
Network APIs
Encoding APIs
Stream APIs
Crypto APIs
Web Standard APIs
All standard JavaScript globals are available:Array, ArrayBuffer, Boolean, Date, Error, JSON, Map, Math, Number, Object, Promise, Proxy, RegExp, Set, String, Symbol, URL, URLPattern, URLSearchParams, WeakMap, WeakSet, WebAssembly, timer functions (clearInterval, clearTimeout, setInterval, setTimeout), encoding helpers (decodeURI, decodeURIComponent, encodeURI, encodeURIComponent), typed arrays, AbortController, console, DOMException, queueMicrotask, structuredClone, and more.
Next.js polyfills
AsyncLocalStorage(Node.jsasync_hooksAPI)
Environment variables
process.env is available in both next dev and next build.
Unsupported APIs
The following are not available in the Edge Runtime:- Native Node.js APIs (filesystem,
cryptomodule,Buffer, etc.) - CommonJS
require()— use ES moduleimportinstead node_modulespackages that use native Node.js APIs
Allowing dynamic code evaluation
In rare cases where code contains unreachable dynamic evaluation, you can suppress the build error usingunstable_allowDynamic in your Proxy config:
proxy.ts
