#edge runtime's node compatibility
1 messages · Page 1 of 1 (latest)
Hi @hallow trout. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
The Edge Runtime in Next.js is compatible with a subset of Node.js modules. The following modules can be imported with and without the node: prefix when using the import statement:
async_hooks(https://nodejs.org/api/async_hooks.html): Manage asynchronous resources lifecycles withAsyncLocalStorage. 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 withBuffer. Every primitive compatible withUint8ArrayacceptsBuffertoo.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 includepromisify/callbackifyandtypes.
Also, Buffer is globally exposed to maximize compatibility with existing Node.js modules.
Please note that the Edge Runtime does not support all Node.js APIs, meaning some npm packages may not work. For example, you might encounter errors like "Module not found: Can't resolve 'fs'" or similar. If you need to use these APIs or packages, it's recommended to use the Node.js runtime instead.