Unverified Commit 2adc1f6c authored by Javi Velasco's avatar Javi Velasco Committed by GitHub

Document node.js APIs for Edge Runtime (#47760)

parent 53e4627c
...@@ -126,10 +126,6 @@ The Edge Runtime supports the following web standard APIs: ...@@ -126,10 +126,6 @@ The Edge Runtime supports the following web standard APIs:
| [`WeakSet`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet) | Represents a collection of objects in which each object may occur only once | | [`WeakSet`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet) | Represents a collection of objects in which each object may occur only once |
| [`WebAssembly`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly) | Provides access to WebAssembly | | [`WebAssembly`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly) | Provides access to WebAssembly |
## Next.js Specific Polyfills
- [`AsyncLocalStorage`](https://nodejs.org/api/async_context.html#class-asynclocalstorage)
## Environment Variables ## Environment Variables
You can use `process.env` to access [Environment Variables](/docs/basic-features/environment-variables.md) for both `next dev` and `next build`. You can use `process.env` to access [Environment Variables](/docs/basic-features/environment-variables.md) for both `next dev` and `next build`.
...@@ -143,11 +139,25 @@ console.log(process.env.TEST_VARIABLE) ...@@ -143,11 +139,25 @@ console.log(process.env.TEST_VARIABLE)
// value // value
``` ```
## Compatible Node.js Modules
The following modules can be imported with and without the `node:` prefix when using the `import` statement:
| Module | Description |
| -------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`async_hooks`](https://nodejs.org/api/async_hooks.html) | Manage asynchronous resources lifecycles with `AsyncLocalStorage`. Supports the [WinterCG subset](https://github.com/wintercg/proposal-common-minimum-api/blob/main/asynclocalstorage.md) of APIs |
| [`events`](https://nodejs.org/api/events.html) | Facilitate event-driven programming with custom event emitters and listeners. This API is fully supported |
| [`buffer`](https://nodejs.org/api/buffer.html) | Efficiently manipulate binary data using fixed-size, raw memory allocations with `Buffer`. Every primitive compatible with `Uint8Array` accepts `Buffer` too |
| [`assert`](https://nodejs.org/api/assert.html) | Provide a set of assertion functions for verifying invariants in your code |
| [`util`](https://nodejs.org/api/util.html) | Offer various utility functions where we include `promisify`/`callbackify` and `types` |
Also, `Buffer` and `AsyncLocalStorage` are globally exposed to maximize compatibility with existing Node.js nodules.
## Unsupported APIs ## Unsupported APIs
The Edge Runtime has some restrictions including: 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 - Some Node.js APIs other than the ones listed above **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 - `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 - Calling `require` directly is **not allowed**. Use ES Modules instead
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment