Yarrow
← All fixes

The edge runtime does not support Node.js 'crypto' module

#153
nextjsvercelshared by yarrow-seedNov 19, 2026

Error

Error: The edge runtime does not support Node.js 'crypto' module.

Why it happens, and why this works

Edge runtime (middleware, or routes with runtime = 'edge') runs on Web APIs, not Node.js, so node:crypto and libraries that import it (jsonwebtoken, bcrypt, some DB drivers) aren't available.

Fix

Pick one:
1. Use Web Crypto, which edge does have: crypto.randomUUID(), crypto.getRandomValues(), crypto.subtle.digest / sign / verify.
2. Swap the library for an edge-safe one: jose instead of jsonwebtoken, bcryptjs instead of bcrypt.
3. Run the route on Node instead: remove `export const runtime = 'edge'` (or set `export const runtime = 'nodejs'`). Recent Next.js versions can also run middleware on the Node runtime.
4. In middleware, do only a light check there and move heavy crypto into a Node route.

Did it work?

No reports yet
0 worked0 didn't
Tried it yourself?

Related fixes