Skip to content
Last updated on March 2, 2023
3 min read

Edge Middleware Limitations

Learn about the limitations of using Edge Middleware with Vercel.

Edge Middleware is neither a Node.js nor browser application and so we have created a custom API that is a subset of browser APIs. There are some restrictions to writing Edge Middleware, which are documented in the Middleware API guide, but to summarize:

  • Use ES modules.
  • Libraries using Node.js APIs can't be used in Edge Middleware. See available APIs.
  • Dynamic code execution (such as eval) is not allowed (see the next section for more details).

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

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

Most importantly, you need to make sure libraries used in your Edge Middleware don't rely on dynamic code execution because it leads to a runtime error.

The maximum duration for Edge Middleware execution is 5 seconds.

This means that you should return a response as soon as possible, and continue with any asynchronous workloads in the background, after returning the response.

Edge Middleware can only use up to 128MiB. If it exceeds this limit, the execution will be aborted and we will return a 502 error.

The maximum size for Edge Middleware is 1 MiB after compression, including your JavaScript code, imported libraries, 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.

While Vercel allows Environment Variables up to a total of 64 KB in size, Edge Middleware are limited to 5KB per Environment Variable.

Maximum URL length
Maximum request body length
4 MiB
Maximum number of request headers
Maximum request headers length

The maximum number of requests from fetch API is 950 per Edge Middleware invocation. only advances after I/O operations (e.g. fetch).

for (let i = 0; i < 1000; i++) {
  console.log(; // Prints the same value 1000 times.
await fetch('');
console.log(; // Prints another value.