Launch offer: everything is 100% off. Download any skill free, no sign-up. Get the skills
TechFixError fixesBroke after deploy
Broke after deploy

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

The error
Error: The edge runtime does not support Node.js 'crypto' module.
Learn More: https://nextjs.org/docs/messages/node-module-in-edge-runtime
Short answer

Code that runs on the Edge runtime imports something built for Node.js (often jsonwebtoken, bcrypt or a database driver). Run that code on the Node.js runtime, or replace the import with a Web Crypto based one.

Why it happens

Next.js can run middleware and routes on a lightweight Edge runtime. It doesn't have Node.js APIs such as crypto, fs or child_process. Any package that uses them breaks there, even if it only imports them indirectly.

Next.js changed the defaults recently. In Next.js 15, middleware.ts defaults to Edge, and the Node.js runtime for middleware became stable in 15.5. In Next.js 16, middleware is renamed to proxy.ts, which runs on Node.js by default.

Fix it by hand

  1. Find the import. Run next dev: Next.js shows in the console and the browser which file imports the unsupported module.
  2. On Next.js 16, rename middleware to proxy with the official codemod. Proxy runs on Node.js, and setting a runtime option in it throws an error, so remove any you had:
    npx @next/codemod@canary middleware-to-proxy .
  3. On Next.js 15.5 or later, keep middleware.ts and switch it to Node.js:
    export const config = {
      runtime: 'nodejs',
      matcher: ['/dashboard/:path*'],
    }
  4. In a route that sets export const runtime = 'edge', remove that line unless you need Edge. Routes run on Node.js by default.
  5. If the code must stay on Edge, replace the Node import. Use the Web Crypto API (crypto.subtle, crypto.getRandomValues) instead of node:crypto, and a JWT library built for Web-interoperable runtimes, such as jose, instead of jsonwebtoken.
  6. Run next build locally and confirm the error is gone before you redeploy.

Stop it happening again

Let TechFix do this for you

Broke After Deploy $9

Broke After Deploy flags Node-only packages and APIs used in middleware or edge routes, and runs your production build to catch what slips through.

  • Checks your project for 37 known causes of "works locally, breaks in production" and runs your production build.
  • Paste the error and it finds the cause in your code, then lists what will break next.
  • Verdict first. Every finding shows the file and line, what it breaks, and the fix as a diff that is applied only with your OK.

Broke After Deploy: how it works, with examples · Install guide

Works with Claude Code, Claude.ai, Cursor, Codex and other agents that read SKILL.md files. No installs, no accounts, works offline. No-questions refund.

Sources (checked 2026-10-13)