# Error: getInitialProps is not supported in the app/ directory. Use generateMetadata, generateStaticParams, or server components instead.

- **ID:** `nextjs/app-dir-getinitialprops-legacy`
- **Domain:** nextjs
- **Category:** breaking_change
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

The app/ directory uses a new routing model that does not support getInitialProps, which was a legacy Pages Router feature. Developers migrating from pages/ to app/ mistakenly use getInitialProps.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Next.js 13.x | active | — | — |
| Next.js 14.x | active | — | — |
| Next.js 15.x | active | — | — |

## Workarounds

1. **Replace getInitialProps with server component data fetching: directly fetch data in the component body using async/await. For dynamic metadata, use generateMetadata.** (90% success)
   ```
   Replace getInitialProps with server component data fetching: directly fetch data in the component body using async/await. For dynamic metadata, use generateMetadata.
   ```
2. **If the data is needed on every page, use a root layout with a server component that fetches data and passes it via context or props.** (85% success)
   ```
   If the data is needed on every page, use a root layout with a server component that fetches data and passes it via context or props.
   ```

## Dead Ends

- **** — The app router explicitly disallows getInitialProps; it will throw this error at build or runtime. (90% fail)
- **** — Even if the component is imported, its getInitialProps will not run; the app router ignores it entirely. (70% fail)
- **** — getServerSideProps is also not supported in app/; it must be replaced with server components or fetch with cache options. (60% fail)
