Edge Runtime
The Next.js Edge Runtime is based on standard Web APIs, which is used by Middleware and Edge API Routes.
Network APIs
Encoding APIs
Web Stream APIs
- ReadableStream
- ReadableStreamBYOBReader
- ReadableStreamDefaultReader
- TransformStream
- WritableStream
- WritableStreamDefaultWriter
Web Crypto APIs
Web Standards APIs
V8 Primitives
- Array
- ArrayBuffer
- Atomics
- BigInt
- BigInt64Array
- BigUint64Array
- Boolean
- clearInterval
- clearTimeout
- console
- DataView
- Date
- decodeURI
- decodeURIComponent
- encodeURI
- encodeURIComponent
- Error
- EvalError
- Float32Array
- Float64Array
- Function
- Infinity
- Int8Array
- Int16Array
- Int32Array
- Intl
- isFinite
- isNaN
- JSON
- Map
- Math
- Number
- Object
- parseFloat
- parseInt
- Promise
- Proxy
- RangeError
- ReferenceError
- Reflect
- RegExp
- Set
- setInterval
- setTimeout
- SharedArrayBuffer
- String
- Symbol
- SyntaxError
- TextDecoder
- TextEncoder
- TypeError
- Uint8Array
- Uint8ClampedArray
- Uint16Array
- Uint32Array
- URIError
- URL
- URLSearchParams
- WeakMap
- WeakSet
- WebAssembly
Environment Variables
You can use process.env
to access Environment Variables for both next dev
and next build
.
Running console.log
on process.env
will not show all your Environment Variables. You have to access the variables directly as shown below:
console.log(process.env)
// { NEXT_RUNTIME: 'edge' }
console.log(process.env.TEST_VARIABLE)
// { NEXT_RUNTIME: 'edge', TEST_VARIABLE: 'value' }
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:
eval
: Evaluates JavaScript code represented as a stringnew Function(evalString)
: Creates a new function with the code provided as an argumentWebAssembly.compile
WebAssembly.instantiate
with a buffer parameter
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: 'experimental-edge', // for Edge API Routes only
unstable_allowDynamic: [
'/lib/utilities.js', // allows a single file
'/node_modules/function-bind/**', // use a glob to allow anything in the function-bind 3rd party module
],
}
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.
Related
MiddlewareRun code before a request is completed.
Middleware API ReferenceLearn more about the supported APIs for Middleware.