{
  "id": "nextjs/edge-function-cannot-access-node-module",
  "signature": "Error: The edge runtime does not support Node.js 'X' module.",
  "signature_zh": "错误：边缘运行时不支持 Node.js 'X' 模块。",
  "regex": "Error: The edge runtime does not support Node.js '.*' module\\.",
  "domain": "nextjs",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A module or API route configured with 'runtime: edge' tries to import a Node.js built-in module (e.g., 'fs', 'crypto', 'path') that is not available in the Edge Runtime.",
  "root_cause_type": "generic",
  "root_cause_zh": "配置了 'runtime: edge' 的模块或 API 路由尝试导入 Edge Runtime 中不可用的 Node.js 内置模块（例如 'fs'、'crypto'、'path'）。",
  "versions": [
    {
      "version": "Next.js 13.5",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Next.js 14.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Next.js 14.2",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Next.js 15.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "'use client' does not change the runtime context; the edge runtime still blocks Node.js modules. The error persists because the module is loaded at build time or runtime.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Changing the runtime alone does not resolve the import issue; the module must be replaced or polyfilled. The error may change to a different module-related error.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Edge Runtime has a specific Web API subset; browser polyfills often use Node.js APIs internally and still fail. The polyfill may not be compatible with the edge sandbox.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Remove the Node.js module import and use Edge-compatible alternatives. For example, replace 'crypto' with the Web Crypto API: 'const key = await crypto.subtle.generateKey(...)'.",
      "success_rate": 0.8,
      "how": "Remove the Node.js module import and use Edge-compatible alternatives. For example, replace 'crypto' with the Web Crypto API: 'const key = await crypto.subtle.generateKey(...)'.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Change the runtime to 'nodejs' in the route segment config: export const runtime = 'nodejs'; then keep the Node.js module import.",
      "success_rate": 0.7,
      "how": "Change the runtime to 'nodejs' in the route segment config: export const runtime = 'nodejs'; then keep the Node.js module import.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use dynamic imports with 'ssr: false' for the Node.js module inside a client component, but ensure the route is not edge-runtime.",
      "success_rate": 0.6,
      "how": "Use dynamic imports with 'ssr: false' for the Node.js module inside a client component, but ensure the route is not edge-runtime.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "移除 Node.js 模块导入并使用边缘兼容的替代方案。例如，用 Web Crypto API 替换 'crypto'：'const key = await crypto.subtle.generateKey(...)'。",
    "在路由段配置中将运行时更改为 'nodejs'：export const runtime = 'nodejs'; 然后保留 Node.js 模块导入。",
    "在客户端组件中对 Node.js 模块使用带有 'ssr: false' 的动态导入，但确保路由不是边缘运行时。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://nextjs.org/docs/app/api-reference/edge",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.75,
  "resolvable": "partial",
  "first_seen": "2023-10-15",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}