Skip to content
Latchkey

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.

next build
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.ts

Common 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

  1. Replace Node APIs with Web equivalents (for example the Web Crypto crypto.subtle).
  2. If the logic needs Node, move it into a route handler that runs on the Node runtime.
  3. Re-run next build.
middleware.ts
// 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.

app/api/route.ts
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.

Frequently asked questions

What causes ""not supported in the Edge Runtime""?
Modules like crypto, fs, or a library that depends on them are unavailable in the Edge Runtime.
How do I fix "not supported in the Edge Runtime"?
Use Web APIs or move the work off the edge

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card