7

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?

MiguelSlv
  • 14,067
  • 15
  • 102
  • 169
  • 1
    You can't use server-side rendering (`getServerSideProps`) when statically exporting a Next.js app with `next export`. See https://nextjs.org/docs/advanced-features/static-html-export#unsupported-features. – juliomalves Apr 17 '22 at 17:00

2 Answers2

4

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

3

Won´t work on page _error.js, by design decision, as posted here by nextjs maintenance staff.

One possibility is to use getInitialProps, instead.

MiguelSlv
  • 14,067
  • 15
  • 102
  • 169
  • But Next Js is recommending not to use `getInitialProps` https://nextjs.org/docs/api-reference/data-fetching/getInitialProps – Deep Kakkar Nov 02 '21 at 04:30