Skip to content

    Edge Runtime

    The Next.js Edge Runtime is based on standard Web APIs, it supports the following APIs:

    Network APIs

    APIDescription
    fetchFetches a resource
    RequestRepresents an HTTP request
    ResponseRepresents an HTTP response
    HeadersRepresents HTTP headers
    FetchEventRepresents a fetch event
    addEventListenerAdds an event listener
    FormDataRepresents form data
    FileRepresents a file
    BlobRepresents a blob
    URLSearchParamsRepresents URL search parameters

    Encoding APIs

    APIDescription
    TextEncoderEncodes a string into a Uint8Array
    TextDecoderDecodes a Uint8Array into a string
    atobDecodes a base-64 encoded string
    btoaEncodes a string in base-64

    Stream APIs

    APIDescription
    ReadableStreamRepresents a readable stream
    WritableStreamRepresents a writable stream
    WritableStreamDefaultWriterRepresents a writer of a WritableStream
    TransformStreamRepresents a transform stream
    ReadableStreamDefaultReaderRepresents a reader of a ReadableStream
    ReadableStreamBYOBReaderRepresents a reader of a ReadableStream

    Crypto APIs

    APIDescription
    cryptoProvides access to the cryptographic functionality of the platform
    SubtleCryptoProvides access to common cryptographic primitives, like hashing, signing, encryption or decryption
    CryptoKeyRepresents a cryptographic key

    Web Standard APIs

    APIDescription
    AbortControllerAllows you to abort one or more DOM requests as and when desired
    DOMExceptionRepresents an error that occurs in the DOM
    structuredCloneCreates a deep copy of a value
    URLPatternRepresents a URL pattern
    ArrayRepresents an array of values
    ArrayBufferRepresents a generic, fixed-length raw binary data buffer
    AtomicsProvides atomic operations as static methods
    BigIntRepresents a whole number with arbitrary precision
    BigInt64ArrayRepresents a typed array of 64-bit signed integers
    BigUint64ArrayRepresents a typed array of 64-bit unsigned integers
    BooleanRepresents a logical entity and can have two values: true and false
    clearIntervalCancels a timed, repeating action which was previously established by a call to setInterval()
    clearTimeoutCancels a timed, repeating action which was previously established by a call to setTimeout()
    consoleProvides access to the browser's debugging console
    DataViewRepresents a generic view of an ArrayBuffer
    DateRepresents a single moment in time in a platform-independent format
    decodeURIDecodes a Uniform Resource Identifier (URI) previously created by encodeURI or by a similar routine
    decodeURIComponentDecodes a Uniform Resource Identifier (URI) component previously created by encodeURIComponent or by a similar routine
    encodeURIEncodes a Uniform Resource Identifier (URI) by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character
    encodeURIComponentEncodes a Uniform Resource Identifier (URI) component by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character
    ErrorRepresents an error when trying to execute a statement or accessing a property
    EvalErrorRepresents an error that occurs regarding the global function eval()
    Float32ArrayRepresents a typed array of 32-bit floating point numbers
    Float64ArrayRepresents a typed array of 64-bit floating point numbers
    FunctionRepresents a function
    InfinityRepresents the mathematical Infinity value
    Int8ArrayRepresents a typed array of 8-bit signed integers
    Int16ArrayRepresents a typed array of 16-bit signed integers
    Int32ArrayRepresents a typed array of 32-bit signed integers
    IntlProvides access to internationalization and localization functionality
    isFiniteDetermines whether a value is a finite number
    isNaNDetermines whether a value is NaN or not
    JSONProvides functionality to convert JavaScript values to and from the JSON format
    MapRepresents a collection of values, where each value may occur only once
    MathProvides access to mathematical functions and constants
    NumberRepresents a numeric value
    ObjectRepresents the object that is the base of all JavaScript objects
    parseFloatParses a string argument and returns a floating point number
    parseIntParses a string argument and returns an integer of the specified radix
    PromiseRepresents the eventual completion (or failure) of an asynchronous operation, and its resulting value
    ProxyRepresents an object that is used to define custom behavior for fundamental operations (e.g. property lookup, assignment, enumeration, function invocation, etc)
    RangeErrorRepresents an error when a value is not in the set or range of allowed values
    ReferenceErrorRepresents an error when a non-existent variable is referenced
    ReflectProvides methods for interceptable JavaScript operations
    RegExpRepresents a regular expression, allowing you to match combinations of characters
    SetRepresents a collection of values, where each value may occur only once
    setIntervalRepeatedly calls a function, with a fixed time delay between each call
    setTimeoutCalls a function or evaluates an expression after a specified number of milliseconds
    SharedArrayBufferRepresents a generic, fixed-length raw binary data buffer
    StringRepresents a sequence of characters
    SymbolRepresents a unique and immutable data type that is used as the key of an object property
    SyntaxErrorRepresents an error when trying to interpret syntactically invalid code
    TypeErrorRepresents an error when a value is not of the expected type
    Uint8ArrayRepresents a typed array of 8-bit unsigned integers
    Uint8ClampedArrayRepresents a typed array of 8-bit unsigned integers clamped to 0-255
    Uint32ArrayRepresents a typed array of 32-bit unsigned integers
    URIErrorRepresents an error when a global URI handling function was used in a wrong way
    URLRepresents an object providing static methods used for creating object URLs
    URLSearchParamsRepresents a collection of key/value pairs
    WeakMapRepresents a collection of key/value pairs in which the keys are weakly referenced
    WeakSetRepresents a collection of objects in which each object may occur only once
    WebAssemblyProvides access to WebAssembly

    Next.js Specific Polyfills

    Environment Variables

    You can use process.env to access Environment Variables for both next dev and next build.

    Unsupported APIs

    The Edge Runtime has some restrictions including:

    • Native Node.js APIs are not supported. For example, you can't read or write to the filesystem.
    • node_modules can be used, as long as they implement ES Modules and do not use native Node.js APIs.
    • Calling require directly is not allowed. Use ES Modules instead.

    The following JavaScript language features are disabled, and will not work:

    APIDescription
    evalEvaluates JavaScript code represented as a string
    new Function(evalString)Creates a new function with the code provided as an argument
    WebAssembly.compileCompiles a WebAssembly module from a buffer source
    WebAssembly.instantiateCompiles and instantiates a WebAssembly module from a buffer source

    In rare cases, your code could contain (or import) some dynamic code evaluation statements which can not be reached at runtime and which can not be removed by treeshaking. You can relax the check to allow specific files with your Middleware or Edge API Route exported configuration:

    export const config = {
      runtime: 'edge', // for Edge API Routes only
      unstable_allowDynamic: [
        // allows a single file
        '/lib/utilities.js',
        // use a glob to allow anything in the function-bind 3rd party module
        '/node_modules/function-bind/**',
      ],
    };

    unstable_allowDynamic is a glob, or an array of globs, ignoring dynamic code evaluation for specific files. The globs are relative to your application root folder.

    Be warned that if these statements are executed on the Edge, they will throw and cause a runtime error.

    Was this helpful?