{
  "id": "nextjs/duplicate-export-metadata-layout",
  "signature": "Error: Duplicate export 'metadata' in layout. Only one 'metadata' export is allowed per layout file.",
  "signature_zh": "错误：布局文件中重复导出 'metadata'。每个布局文件只允许一个 'metadata' 导出。",
  "regex": "Duplicate export 'metadata' in layout",
  "domain": "nextjs",
  "category": "build_error",
  "subcategory": null,
  "root_cause": "A layout file (layout.tsx) contains multiple exports named 'metadata' (e.g., both a static metadata object and a generateMetadata function), which is disallowed because Next.js expects exactly one metadata definition per layout.",
  "root_cause_type": "generic",
  "root_cause_zh": "布局文件（layout.tsx）包含多个名为 'metadata' 的导出（例如，同时有静态 metadata 对象和 generateMetadata 函数），这是不允许的，因为 Next.js 每个布局只期望一个 metadata 定义。",
  "versions": [
    {
      "version": "Next.js 13.4.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Next.js 14.0.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Next.js 14.2.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Next.js explicitly rejects duplicate exports during build; the build will fail with the same error.",
      "fail_rate": 1.0,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Next.js only recognizes exports named exactly 'metadata' or 'generateMetadata'; renamed exports are ignored, so the metadata won't be applied.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The error is about the export name in the layout file itself; importing from another file still results in a single named export in the layout, so the duplicate is resolved, but if both are imported and re-exported, the same error occurs.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Remove the static metadata export and keep only the generateMetadata function. Example: In layout.tsx, delete `export const metadata = { title: '...' }` and keep `export async function generateMetadata() { return { title: '...' }; }`.",
      "success_rate": 0.95,
      "how": "Remove the static metadata export and keep only the generateMetadata function. Example: In layout.tsx, delete `export const metadata = { title: '...' }` and keep `export async function generateMetadata() { return { title: '...' }; }`.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Remove the generateMetadata function and keep only the static metadata object if no dynamic logic is needed. Example: In layout.tsx, delete the generateMetadata function and keep `export const metadata = { title: '...' }`.",
      "success_rate": 0.9,
      "how": "Remove the generateMetadata function and keep only the static metadata object if no dynamic logic is needed. Example: In layout.tsx, delete the generateMetadata function and keep `export const metadata = { title: '...' }`.",
      "condition": "",
      "sources": []
    },
    {
      "action": "If both static and dynamic metadata are needed, merge them into a single generateMetadata function that returns the combined object, or use a static metadata object with dynamic overrides via generateMetadata in child pages.",
      "success_rate": 0.85,
      "how": "If both static and dynamic metadata are needed, merge them into a single generateMetadata function that returns the combined object, or use a static metadata object with dynamic overrides via generateMetadata in child pages.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "删除静态 metadata 导出，只保留 generateMetadata 函数。示例：在 layout.tsx 中，删除 `export const metadata = { title: '...' }`，保留 `export async function generateMetadata() { return { title: '...' }; }`。",
    "如果不需要动态逻辑，删除 generateMetadata 函数，只保留静态 metadata 对象。示例：在 layout.tsx 中，删除 generateMetadata 函数，保留 `export const metadata = { title: '...' }`。",
    "如果同时需要静态和动态 metadata，将它们合并到一个 generateMetadata 函数中返回组合对象，或者使用静态 metadata 对象并在子页面中通过 generateMetadata 进行动态覆盖。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://nextjs.org/docs/app/building-your-application/optimizing/metadata",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.88,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2023-10-20",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}