# Error: Duplicate export 'metadata' in layout. Only one 'metadata' export is allowed per layout file.

- **ID:** `nextjs/duplicate-export-metadata-layout`
- **Domain:** nextjs
- **Category:** build_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

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

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Next.js 13.4.0 | active | — | — |
| Next.js 14.0.0 | active | — | — |
| Next.js 14.2.0 | active | — | — |

## Workarounds

1. **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: '...' }; }`.** (95% success)
   ```
   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: '...' }; }`.
   ```
2. **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: '...' }`.** (90% success)
   ```
   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: '...' }`.
   ```
3. **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.** (85% success)
   ```
   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.
   ```

## Dead Ends

- **** — Next.js explicitly rejects duplicate exports during build; the build will fail with the same error. (100% fail)
- **** — Next.js only recognizes exports named exactly 'metadata' or 'generateMetadata'; renamed exports are ignored, so the metadata won't be applied. (95% fail)
- **** — 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. (60% fail)
