# Next.js: The edge runtime does not support Node.js 'crypto' module / A Node.js module is loaded ('fs') which is not supported in the Edge Runtime

**Code:** `The edge runtime does not support Node.js module` · **Category:** Next.js · **Seen on:** Next.js, Node.js

Middleware or an Edge route imported a Node.js built-in (`fs`, `crypto`, `path`, `net`) that isn't available on the Edge.

## Meaning

Use Web APIs instead (`crypto.subtle`, `fetch`, `URL`) or move that code to a Node.js runtime route. A dependency of your middleware may import a Node module transitively: check the import trace and replace the package.

## Common causes

- `import crypto from "crypto"` in middleware
- Library depending on `fs`/`path`
- Database drivers (pg, mongoose) in Edge code
- Auth libs using Node crypto
- Shared utils imported by middleware

## Quick fix

1. Use Web Crypto (`crypto.subtle`) in middleware
2. Keep DB access in Node runtime handlers
3. Split shared utils so middleware imports only Edge-safe files

## Detailed fix by platform

### Next.js

1. `export const runtime = "nodejs"; // for routes that need Node APIs`

## How to diagnose

1. **Import** — Which module?
2. **Trace** — Who imports it?
3. **Runtime** — Edge?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/nextjs/edge-runtime-node-module-not-supported)
