Skip to content

Next.js build error

Next.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.

Rather hand it over? App Fix Ticket: One reproducible bug in an existing mobile or web app, diagnosed and fixed.The Fix is $1,200 in total. The $450 Diagnosis is optional and credited toward it.

Full refund if Simon can’t take it on once he sees your project, or if you cancel before work starts. Refund terms.

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.

Rather not fix it yourself? App Fix Ticket fixes one reproducible bug at a fixed price, with an optional Diagnosis that is credited toward the fix.

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.ts to proxy.ts and any named middleware export to proxy. Remove runtime from the config. Proxy runs on Node.js. 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.

“Very responsive, attentive to fixing bugs, and completed the project as needed! Thank you!”
A buyer in the United States, July 2022. Shopify on Fiverr
Read 126 of the 127 Fiverr reviews

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, keep the middleware.ts or middleware.js convention.

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?

The optional Diagnosis costs $450. The Fix is $1,200 in total. If one bug is the whole problem, the App Fix Ticket covers it. If you already know the cause, you can pay for the fix directly; if not, start with a written diagnosis, which is credited toward 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?

Ask Simon for a price range

Send the error and what you were doing. Simon replies by email, usually within one business day, with a price range.