vercel/next.js · error

Detected getInitialProps on page '${pathname}' while running

Error message

Detected getInitialProps on page '${pathname}' while running export. It's recommended to use getStaticProps which has a more correct behavior for static exporting.
Read more: https://nextjs.org/docs/messages/get-initial-props-export

What it means

Error "Detected getInitialProps on page '${pathname}' while running export. It's recommended to use getStaticProps which has a more correct behavior for static exporting. Read more: https://nextjs.org/docs/messages/get-initial-props-export" thrown in vercel/next.js.

Source

Thrown at packages/next/src/server/render.tsx:550

  const defaultAppGetInitialProps =
    App.getInitialProps === (App as any).origGetInitialProps

  const hasPageGetInitialProps = !!(Component as any)?.getInitialProps
  const hasPageScripts = (Component as any)?.unstable_scriptLoader

  const pageIsDynamic = isDynamicRoute(pathname)

  const defaultErrorGetInitialProps =
    pathname === '/_error' &&
    (Component as any).getInitialProps ===
      (Component as any).origGetInitialProps

  if (
    renderOpts.isBuildTimePrerendering &&
    hasPageGetInitialProps &&
    !defaultErrorGetInitialProps
  ) {
    warn(
      `Detected getInitialProps on page '${pathname}'` +
        ` while running export. It's recommended to use getStaticProps` +
        ` which has a more correct behavior for static exporting.` +
        `\nRead more: https://nextjs.org/docs/messages/get-initial-props-export`
    )
  }

  let isAutoExport =
    !hasPageGetInitialProps &&
    defaultAppGetInitialProps &&
    !isSSG &&
    !getServerSideProps

  // if we are running from experimental compile and the page
  // would normally be automatically statically optimized
  // ensure we set cache header so it's not rendered on-demand
  // every request
  if (isAutoExport && !process.env.__NEXT_DEV_SERVER && isExperimentalCompile) {

View on GitHub (pinned to 89d017eac4)

Solutions

  1. Replace getInitialProps with getStaticProps (and getStaticPaths for dynamic pages) for static export compatibility.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/next/src/server/render.tsx:552 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of vercel/next.js@89d017eac4 (2026-08-19). Data as JSON: /api/errors/f7dbf358c615901b. Report an issue: GitHub.