silverwolf-x/project / errors /404-get-initial-props.mdx
silverwolf-x's picture
download
raw
1.34 kB
---
title: 404.js Cannot Have getInitialProps
description: This document provides an understanding of the "404.js Cannot Have getInitialProps" error in Next.js and offers solutions to fix it.
---
## Why This Error Occurred
The "404.js Cannot Have `getInitialProps`" error usually occurs when either `getInitialProps` or `getServerSideProps` is used in your `404.js` page. The `404.js` page in Next.js is designed to be static to ensure consistent performance.
## Possible Ways to Fix It
Adding `getInitialProps` or `getServerSideProps` to your `404.js` page will cause it to be rendered on the server-side.
To fix this error, you should remove `getInitialProps` from your `404.js` page. Additionally, ensure that no Higher-Order Components (HOCs) used in the `404.js` page are attaching `getInitialProps`.
If your `404.js` page requires data fetching, we recommend incrementally adopting the App Router and the [`not-found`](/docs/app/api-reference/file-conventions/not-found) file, which does support fetching data before displaying the 404 page.
## Useful Links
- [Automatic Static Optimization](/docs/pages/building-your-application/rendering/automatic-static-optimization) - Learn more about how Next.js automatically optimizes your pages for better performance.
- [`not-found`](/docs/app/api-reference/file-conventions/not-found)

Xet Storage Details

Size:
1.34 kB
·
Xet hash:
d76e7fada349308cc44a20d653143ab8b0e76913cbfdcac2aa33c7aa6566d633

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.