# 错误：Edge 运行时不支持 Node.js API 'X'。请使用 'edge-runtime' 兼容的 API。

- **ID:** `nextjs/middleware-edge-runtime-node-api`
- **领域:** nextjs
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 95%

## 根因

Next.js 中间件在 Edge 运行时上运行，与 Node.js 相比 API 有限。使用 Node.js 特定模块如 'fs'、'path' 或 'crypto'（没有 Web Crypto）会抛出此错误。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| next@13.4.0 | active | — | — |
| next@14.0.0 | active | — | — |
| next@15.0.0 | active | — | — |

## 解决方案

1. ```
   将依赖 Node.js 的逻辑移出中间件，放入单独的 API 路由或服务器组件中。
   ```
2. ```
   使用 Edge 运行时中可用的 Web API，例如 Web Crypto（crypto.subtle）替代 Node.js crypto。
   ```

## 无效尝试

- **** — The Edge Runtime does not have a file system; any import of 'fs' will fail at runtime. (95% 失败率)
- **** — Dynamic imports also run on the Edge Runtime and are blocked; they don't fall back to Node.js. (90% 失败率)
