Capítulo 444 de 456
API reference for the Edge Runtime, Next.js's limited server runtime (used in Proxy) versus the default Node.js Runtime. Supports a Web Standard-aligned API surface, but not Node.js APIs or ISR.
fetch, Request, Response, Headers, WebSocket, ...), Encoding APIs (TextEncoder, atob/btoa, ...), Stream APIs (ReadableStream, TransformStream, ...), Crypto APIs (crypto, SubtleCrypto, CryptoKey), and a broad set of Web Standard globals (Array, Promise, URL, URLPattern, structuredClone, etc.).AsyncLocalStorage.process.env: available in both next dev and next build on Edge.require() (use ES Modules), eval, new Function(evalString), WebAssembly.compile/instantiate.unstable_allowDynamic: glob(s) in Proxy config to allow specific files containing unreachable dynamic-code-eval statements that can't be tree-shaken.export const config = {
unstable_allowDynamic: [
'/lib/utilities.js',
'**/node_modules/function-bind/**',
],
}
Categorias de API suportadas: Network (Blob, fetch, FetchEvent, File, FormData, Headers, Request, Response, URLSearchParams, WebSocket), Encoding (atob, btoa, TextDecoder(Stream), TextEncoder(Stream)), Stream (ReadableStream(BYOBReader/DefaultReader), TransformStream, WritableStream(DefaultWriter)), Crypto (crypto, CryptoKey, SubtleCrypto), Web Standard (globals JS padrão: Array, Date, JSON, Map, Set, Promise, Proxy, RegExp, URL, URLPattern, WeakMap/WeakSet, WebAssembly, timers, erros, etc.)
require() diretamente no Edge Runtime: não é permitido; use ES Modules.node_modules que dependem de APIs nativas do Node: só funcionam se implementarem ES Modules puros sem APIs nativas.eval/new Function/WebAssembly.compile/instantiate no Edge: desabilitados, lançam erro em runtime se executados.unstable_allowDynamic é uma válvula de escape pra código dinâmico inalcançável que o tree-shaking não consegue remover, mas não protege contra execução real (isso ainda quebra em runtime).output.edgeRuntime.unstable_allowDynamic e o Edge Runtime são configurados.