Skip to content

Next.js build errorNext.js: “The edge runtime does not support Node.js 'crypto' module”

Your middleware or an Edge route imports something that needs Node.js, often crypto, a JWT library or a database client, and Next.js stops with The edge runtime does not support Node.js 'crypto' module (or another module name). The Edge Runtime only has Web APIs. On older Next.js versions middleware always ran there; newer versions let it run on Node.js.

Short answer

Either stop using the Node.js API in that file or move the file to the Node.js runtime. Replace crypto with the Web Crypto API (crypto.subtle) and a Node-only JWT library with an Edge-ready one such as jose. On Next.js 15.5, add export const config = { runtime: 'nodejs' } to middleware.ts; on Next.js 16, rename middleware to proxy, which always runs on Node.js. Next.js dev shows which file imports the module.

Why the module is rejected, and the fix

  1. 01

    Middleware or an Edge route uses a Node.js API

    “The code in your Proxy or your Edge API Routes is using a feature from Node.js runtime. However, the Edge Runtime does not support Node.js APIs and globals.” Next.js, Using Node.js Modules in Edge Runtime

    Code that runs on the Edge Runtime can only use Web APIs. Importing crypto, fs, a Node-only JWT or database library, or anything that pulls one in, breaks the build or the request. In next dev, the console and the browser name the file that imports the module.

  2. 02

    Swap the Node API for a Web API

    “For example, you might replace the Node.js crypto module with the Web Crypto API.” Next.js, Using Node.js Modules in Edge Runtime

    For hashing or signing, use crypto.subtle, which works on Edge and in browsers. For JWTs, use a library built on Web Crypto, such as jose, in place of jsonwebtoken. Keep database calls out of middleware and do them in a route handler or server component that runs on Node.js.

    // works on the Edge Runtime
    const data = new TextEncoder().encode(token);
    const digest = await crypto.subtle.digest('SHA-256', data);
  3. 03

    Next.js 15.5 and later: run middleware on Node.js

    “As of v15.5, we have support for using the Node.js runtime. To enable, in your middleware file, set the runtime to nodejs in the config object” Next.js, middleware.js (Next.js 15)

    If the code really needs Node.js, switch the runtime. On Next.js 15.5, middleware still defaults to Edge: add the config below to middleware.ts. On Next.js 16, rename middleware to proxy, which runs on Node.js with no config; the codemod npx @next/codemod@canary middleware-to-proxy . does the rename. Route handlers that set runtime = 'edge' are not changed by the rename; remove that line if they need Node.js.

    // middleware.ts on Next.js 15.5
    export const config = {
      runtime: 'nodejs',
    };
  4. 04

    Or drop the import from the Edge file

    “This module must be avoided: either by not importing it, or by replacing it with a polyfill.” Next.js, Using Node.js Modules in Edge Runtime

    Sometimes the Node module comes in through a shared helper file that middleware imports for one small function. Split that helper so the Edge file only imports what it needs, or move the work out of middleware.

Checked against the vendor’s docs on : Next.js: Using Node.js Modules in Edge Runtime; Next.js: proxy.js file convention (runtime and version history); Next.js 15: middleware.js (Node.js runtime from v15.5); Next.js: upgrading to version 16 (middleware to proxy).

Rather hand it over?

Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.

Related: Next.js Module not found: Can’t resolve fs · Next.js DynamicServerError at build · Vercel npm run build exited with 1 · Node.js ERR_MODULE_NOT_FOUND

Questions

More on this error

Do I have to rename middleware.ts to proxy.ts?

On Next.js 16 the middleware file is deprecated and renamed to proxy, and proxy always runs on Node.js. Next.js says to keep using middleware if you still need the Edge runtime. On Next.js 15, middleware.ts is the only option.

Will moving to the Node.js runtime slow my site?

Proxy and middleware run on every matching request, so keep the work in them small whichever runtime you use. Do heavy work such as database queries in route handlers or server components.

Can you fix it for me?

If one bug is the whole problem, the App Fix Ticket covers it: a written diagnosis first, then the fix. If the app has more going on, the Launch Check is a written check of the whole app. Each issue found is rated critical, high, medium or low, with where it is and how it was confirmed. No issues worth fixing, no charge. If the Launch Check finds nothing rated medium or higher, Simon refunds the full $450. You keep the report either way. This applies to the first 10 Launch Checks bought after October 30, 2026.

A different error?

Describe it and get a written quote

Send the error and what you were doing. You get a written scope, a fixed price and a timeline; Simon replies by email, usually within one business day.