← All fixes
The edge runtime does not support Node.js 'crypto' module
#153Error
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 yet0 worked0 didn't
Tried it yourself?
Related fixes
node --test <folder>/ fails with Cannot find module on Node 22+
#17Error: Cannot find module '/path/to/project/tests' (MODULE_NOT_FOUND) when running node --test tests/
nodeVerifiedNo reports yet
node --test can't import project files: Cannot use import statement outside a module
#7SyntaxError: Cannot use import statement outside a module (or ERR_REQUIRE_ESM) when running node --test against lib/*.js files that use import/export.
Named export not found: the requested module is a CommonJS module
#27SyntaxError: Named export 'greet' not found. The requested module './lib.cjs' is a CommonJS module, which may not support all module.exports as named exports.
nodeVerifiedNo reports yet