Menu
Important
Stay updated on React2Shell

Edge Runtime

Last updated October 27, 2025

We recommend migrating from edge to Node.js for improved performance and reliability. Both runtimes run on Fluid compute with Active CPU pricing.

To convert your Vercel Function to use the Edge runtime, add the following code to your function:

If you're not using a framework, you must either add "type": "module" to your package.json or change your JavaScript Functions' file extensions from .js to .mjs

By default, Vercel Functions using the Edge runtime execute in the region closest to the incoming request. You can set one or more preferred regions using the route segment config or specify a key within a config object to set one or more regions for your functions to execute in.

If your function depends on a data source, you may want it to be close to that source for fast responses.

To configure which region (or multiple regions) you want your function to execute in, pass the ID of your preferred region(s) in the following way:

If you're not using a framework, you must either add "type": "module" to your package.json or change your JavaScript Functions' file extensions from .js to .mjs

In the event of regional downtime, Vercel will automatically reroute traffic to the next closest CDN region on all plans. For more information on which regions Vercel routes traffic to, see Outage Resiliency.

Vercel Functions using the Edge runtime must begin sending a response within 25 seconds to maintain streaming capabilities beyond this period, and can continue streaming data for up to 300 seconds.

Vercel automatically scales your functions to handle traffic surges, ensuring optimal performance during increased loads. For more information, see Concurrency scaling.

The Edge runtime is built on top of the V8 engine, allowing it to run in isolated execution environments that don't require a container or virtual machine.

The Edge runtime provides a subset of Web APIs such as , , and .

The following tables list the APIs that are available in the Edge runtime.

APIDescription
Fetches a resource
Represents an HTTP request
Represents an HTTP response
Represents HTTP headers
Represents form data
Represents a file
Represents a blob
Represents URL search parameters
Represents a blob
Represents an event
Represents an object that can handle events
Represents an event that is sent to the global scope of a script when a JavaScript Promise is rejected
APIDescription
Encodes a string into a Uint8Array
Decodes a Uint8Array into a string
Decodes a base-64 encoded string
Encodes a string in base-64
APIDescription
Represents a readable stream
Represents a writable stream
Represents a writer of a WritableStream
Represents a transform stream
Represents a reader of a ReadableStream
Represents a reader of a ReadableStream
APIDescription
Provides access to the cryptographic functionality of the platform
Provides access to common cryptographic primitives, like hashing, signing, encryption or decryption
Represents a cryptographic key
APIDescription
Allows you to abort one or more DOM requests as and when desired
Represents a signal object that allows you to communicate with a DOM request (such as a request) and abort it if required
Represents an error that occurs in the DOM
Creates a deep copy of a value
Represents a URL pattern
Represents an array of values
Represents a generic, fixed-length raw binary data buffer
Provides atomic operations as static methods
Represents a whole number with arbitrary precision
Represents a typed array of 64-bit signed integers
Represents a typed array of 64-bit unsigned integers
Represents a logical entity and can have two values: and
Cancels a timed, repeating action which was previously established by a call to
Cancels a timed, repeating action which was previously established by a call to
Provides access to the browser's debugging console
Represents a generic view of an
Represents a single moment in time in a platform-independent format
Decodes a Uniform Resource Identifier (URI) previously created by or by a similar routine
Decodes a Uniform Resource Identifier (URI) component previously created by or by a similar routine
Encodes 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
Encodes 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
Represents an error when trying to execute a statement or accessing a property
Represents an error that occurs regarding the global function
Represents a typed array of 32-bit floating point numbers
Represents a typed array of 64-bit floating point numbers
Represents a function
Represents the mathematical Infinity value
Represents a typed array of 8-bit signed integers
Represents a typed array of 16-bit signed integers
Represents a typed array of 32-bit signed integers
Provides access to internationalization and localization functionality
Determines whether a value is a finite number
Determines whether a value is or not
Provides functionality to convert JavaScript values to and from the JSON format
Represents a collection of values, where each value may occur only once
Provides access to mathematical functions and constants
Represents a numeric value
Represents the object that is the base of all JavaScript objects
Parses a string argument and returns a floating point number
Parses a string argument and returns an integer of the specified radix
Represents the eventual completion (or failure) of an asynchronous operation, and its resulting value
Represents an object that is used to define custom behavior for fundamental operations (e.g. property lookup, assignment, enumeration, function invocation, etc)
Represents an error when a value is not in the set or range of allowed values
Represents an error when a non-existent variable is referenced
Provides methods for interceptable JavaScript operations
Represents a regular expression, allowing you to match combinations of characters
Represents a collection of values, where each value may occur only once
Repeatedly calls a function, with a fixed time delay between each call
Calls a function or evaluates an expression after a specified number of milliseconds
Represents a generic, fixed-length raw binary data buffer
Represents a sequence of characters
Represents a unique and immutable data type that is used as the key of an object property
Represents an error when trying to interpret syntactically invalid code
Represents an error when a value is not of the expected type
Represents a typed array of 8-bit unsigned integers
Represents a typed array of 8-bit unsigned integers clamped to 0-255
Represents a typed array of 32-bit unsigned integers
Represents an error when a global URI handling function was used in a wrong way
Represents an object providing static methods used for creating object URLs
Represents a collection of key/value pairs
Represents a collection of key/value pairs in which the keys are weakly referenced
Represents a collection of objects in which each object may occur only once
Provides access to WebAssembly

You can check if your function is running on the Edge runtime by checking the global property. This can be helpful if you need to validate that your function is running on the Edge runtime in tests, or if you need to use a different API depending on the runtime.

The following modules can be imported with and without the prefix when using the statement:

ModuleDescription
Manage asynchronous resources lifecycles with . Supports the WinterCG subset of APIs
Facilitate event-driven programming with custom event emitters and listeners. This API is fully supported
Efficiently manipulate binary data using fixed-size, raw memory allocations with . Every primitive compatible with accepts too
Provide a set of assertion functions for verifying invariants in your code
Offer various utility functions where we include / and

Also, is globally exposed to maximize compatibility with existing Node.js modules.

The Edge runtime has some restrictions including:

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

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

APIDescription
Evaluates JavaScript code represented as a string
Creates a new function with the code provided as an argument
Compiles a WebAssembly module from a buffer source
Compiles and instantiates a WebAssembly module from a buffer source

While is supported in Edge Runtime, it requires the Wasm source code to be provided using the import statement. This means you cannot use a buffer or byte array to dynamically compile the module at runtime.

You can use to access Environment Variables.

Middleware with the runtime configured is neither a Node.js nor browser application, which means it doesn't have access to all browser and Node.js APIs. Currently, our runtime offers a subset of browser APIs and some Node.js APIs and we plan to implement more functionality in the future.

In summary:

  • Use ES modules
  • Most libraries that use Node.js APIs as dependencies can't be used in Middleware with the runtime configured.
  • Dynamic code execution (such as ) is not allowed (see the next section for more details)

Dynamic code execution is not available in Middleware with the runtime configured for security reasons. For example, the following APIs cannot be used:

APIDescription
Evaluates JavaScript code represented as a string
Creates a new function with the code provided as an argument
Compiles and instantiates a WebAssembly module from a buffer source

You need to make sure libraries used in your Middleware with the runtime configured don't rely on dynamic code execution because it leads to a runtime error.

Middleware with the runtime configured must begin sending a response within 25 seconds.

You may continue streaming a response beyond that time and you can continue with asynchronous workloads in the background, after returning the response.

PlanLimit (after gzip compression)
Hobby1 MB
Pro2 MB
Enterprise4 MB

The maximum size for an Vercel Function using the Edge runtime includes your JavaScript code, imported libraries and files (such as fonts), and all files bundled in the function.

If you reach the limit, make sure the code you are importing in your function is used and is not too heavy. You can use a package size checker tool like bundle to check the size of a package and search for a smaller alternative.

Environment Variables can be accessed through the object. Since JavaScript objects have methods to allow some operations on them, there are limitations on the names of Environment Variables to avoid having ambiguous code.

The following names will be ignored as Environment Variables to avoid overriding the object prototype:

Therefore, your code will always be able to use them with their expected behavior:


Was this helpful?

supported.