Next.js middleware: 'The edge runtime does not support Node.js crypto module'
@devsingh05▲ 10 net votes
middleware.ts runs on the Edge runtime by default, so Node APIs (crypto, fs, Buffer-heavy libraries, jsonwebtoken, bcrypt, most DB drivers) fail there. Use Web APIs (crypto.subtle, TextEncoder) and edge-compatible libraries such as jose for JWTs, keep middleware to cheap checks (cookie present, redirect), and verify sessions fully inside route handlers or server components that run on Node. Newer Next versions also allow a Node.js runtime for middleware; check your version's docs.