'Pages with `getServerSideProps` can not be exported
I think i am making some kind of confusion here.
According to the documentation, if i want Server Side Rendering (SSR) for the page i export the async function:
getServerSideProps
But if i do that i can't build the project for running either locally or now Zeit now. If i try build or deploy i get:
Error for page /_error: pages with
getServerSideProps
can not be exported. See more info here: https://err.sh/next.js/gssp-export
The link provided by the error says i can't export. But I used the example from the documentation below:
import React from "react"
export async function getServerSideProps() {
return { props: { } }
}
function Page({ data }) {
// Render data...
}
export default Page
Do i have to change some configuration somewhere?
How to prevent from building this static page?
Solution 1:[1]
Won´t work on page _error.js, by design decision, as posted here by nextjs maintenance staff.
One possibility is to use getInitialProps
, instead.
Solution 2:[2]
getStaticProps()
is the way to go under the following conditions:
- The data required to render the page is available at build time ahead of a user’s request
- The data comes from a headless CMS
- The data can be publicly cached (not user-specific)
- The page must be pre-rendered (for SEO) and be very fast — getStaticProps generates HTML and JSON files, both of which can be cached by a CDN for performance
Refer here for when to use getStaticProps
vs getServerSideProps
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | MiguelSlv |
Solution 2 | Rikesh Thapa |