# Error: Layout segment config 'X' is not allowed. Use generateMetadata or generateStaticParams instead.

- **ID:** `nextjs/layout-segment-config-export`
- **Domain:** nextjs
- **Category:** config_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

In Next.js app directory, layout segment configs like 'layout' or 'template' cannot be exported directly; they must be replaced with the correct data-fetching or metadata APIs.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| next@13.5.0 | active | — | — |
| next@14.0.0 | active | — | — |
| next@14.1.0 | active | — | — |

## Workarounds

1. **Replace the layout segment config with generateMetadata. For example, if you exported 'metadata', change to:

export async function generateMetadata({ params }) {
  const data = await fetchData(params.slug);
  return { title: data.title };
}** (90% success)
   ```
   Replace the layout segment config with generateMetadata. For example, if you exported 'metadata', change to:

export async function generateMetadata({ params }) {
  const data = await fetchData(params.slug);
  return { title: data.title };
}
   ```
2. **If the config was for static generation, use generateStaticParams:

export async function generateStaticParams() {
  const posts = await fetchPosts();
  return posts.map(post => ({ slug: post.slug }));
}** (85% success)
   ```
   If the config was for static generation, use generateStaticParams:

export async function generateStaticParams() {
  const posts = await fetchPosts();
  return posts.map(post => ({ slug: post.slug }));
}
   ```
3. **For dynamic segments, ensure the layout has a default.tsx or loading.tsx to handle fallback states.** (75% success)
   ```
   For dynamic segments, ensure the layout has a default.tsx or loading.tsx to handle fallback states.
   ```

## Dead Ends

- **** — The layout still needs to define metadata or static params; removing the export breaks the page functionality. (70% fail)
- **** — Next.js only recognizes specific exports; arbitrary names are ignored and cause build errors. (90% fail)
- **** — Client components cannot use metadata or static params; this creates a different error. (80% fail)
