Next.js middleware "A Node.js API is used which is not supported in the Edge Runtime" in CI
Next.js middleware and Edge route handlers run in the Edge Runtime, a web-standard environment without Node built-ins. Importing a Node module or using a Node-only API there fails the build.
What this error means
next build fails with "A Node.js API is used (process.version at line: N) which is not supported in the Edge Runtime" or "The edge runtime does not support Node.js 'crypto' module", pointing at middleware or an edge route.
Error: The edge runtime does not support Node.js 'crypto' module.
Learn More: https://nextjs.org/docs/messages/node-module-in-edge-runtime
Import trace:
./middleware.tsCommon causes
A Node-only module is imported in middleware or an edge route
Modules like crypto, fs, or a library that depends on them are unavailable in the Edge Runtime.
A Node global or API is used at the edge
APIs such as process.version or Buffer-specific behavior are not part of the web-standard Edge Runtime.
How to fix it
Use Web APIs or move the work off the edge
- Replace Node APIs with Web equivalents (for example the Web Crypto
crypto.subtle). - If the logic needs Node, move it into a route handler that runs on the Node runtime.
- Re-run next build.
// Web Crypto works at the edge
const digest = await crypto.subtle.digest('SHA-256', data)Run the route on the Node.js runtime
For route handlers (not middleware), opt into the Node runtime so Node modules are available.
export const runtime = 'nodejs'How to prevent it
- Keep middleware free of Node-only modules and globals.
- Use Web standard APIs for edge code.
- Move Node-dependent logic to Node-runtime route handlers.