vercel/next.js · error · Error

Error for page ${page}: ${SERVER_PROPS_EXPORT_ERROR}

Error message

Error for page ${page}: ${SERVER_PROPS_EXPORT_ERROR}

What it means

Thrown by exportPagesPage() when the page component exposes a getServerSideProps function during static export. The SERVER_PROPS_EXPORT_ERROR constant states 'pages with getServerSideProps can not be exported' because getServerSideProps is inherently per-request and cannot be prerendered to a static file. Next.js refuses rather than emit stale or empty HTML.

Source

Thrown at packages/next/src/export/routes/pages.ts:49

  res: MockedResponse,
  path: string,
  page: string,
  query: NextParsedUrlQuery,
  params: Params | undefined,
  htmlFilepath: string,
  htmlFilename: string,
  pagesDataDir: string,
  buildExport: boolean,
  isDynamic: boolean,
  sharedContext: PagesSharedContext,
  renderContext: PagesRenderContext,
  hasOrigQueryValues: boolean,
  renderOpts: RenderOpts,
  components: LoadComponentsReturnType,
  fileWriter: MultiFileWriter
): Promise<ExportRouteResult | undefined> {
  if (components.getServerSideProps) {
    throw new Error(`Error for page ${page}: ${SERVER_PROPS_EXPORT_ERROR}`)
  }

  // for non-dynamic SSG pages we should have already
  // prerendered the file
  if (!buildExport && components.getStaticProps && !isDynamic) {
    return
  }

  // Pages router merges page params (e.g. [lang]) with query params
  // primarily to support them both being accessible on `useRouter().query`.
  // If we extracted dynamic params from the path, we need to merge them
  // back into the query object.
  const searchAndDynamicParams = {
    ...query,
    ...params,
  }

  if (components.getStaticProps && !htmlFilepath.endsWith('.html')) {

View on GitHub (pinned to 0ae8c72462)

Solutions

  1. Convert getServerSideProps to getStaticProps (with getStaticPaths for dynamic routes) so the page can be prerendered.
  2. If the page must stay server-rendered, remove `output: 'export'` and deploy to a Node/Serverless runtime instead.
  3. Move the dynamic data fetching to the client (useEffect/SWR/React Query) so the page itself is static.
  4. Audit _app.tsx and _document.tsx — getServerSideProps there also triggers this error.

Example fix

// before — pages/dashboard.js
export async function getServerSideProps(ctx) {
  const user = await fetchUser(ctx.req)
  return { props: { user } }
}
// after — switch to static + client fetch, or getStaticProps
export async function getStaticProps() {
  const data = await fetchPublicData()
  return { props: { data }, revalidate: 60 }
}
Defensive patterns

Strategy: validation

Validate before calling

// Pre-build check: no getServerSideProps when output:'export' is set
import fs from 'fs'
import path from 'path'
function assertNoGSSPForExport(pagesDir: string, outputMode?: string) {
  if (outputMode !== 'export') return
  for (const f of fs.readdirSync(pagesDir)) {
    const src = fs.readFileSync(path.join(pagesDir, f), 'utf8')
    if (/getServerSideProps/.test(src)) {
      throw new Error(`${f} uses getServerSideProps — incompatible with output:'export'`)
    }
  }
}

Type guard

function isStaticPage(mod: any): boolean {
  return !mod.getServerSideProps && (mod.getStaticProps || !mod.getInitialProps)
}

Try / catch

// Build-time only; catch in CI:
try {
  await exec('next build')
} catch (e) {
  if (/can not be exported/.test(e.message)) {
    console.error('A page exports getServerSideProps — convert to getStaticProps or drop output:export')
  }
  throw e
}

Prevention

When it happens

Trigger: Running `next build` with `output: 'export'` (or `next export`) on a Pages Router project where one or more pages export getServerSideProps. The export worker loads the component, detects getServerSideProps, and throws.

Common situations: Migrating an existing SSR app to fully-static export without rewriting the data-fetching layer; mixing SSG and SSR pages and forgetting that export disallows SSR; or a shared _app/_document hoisting a getServerSideProps. Also seen after enabling output: 'export' on a starter that ships a getServerSideProps demo.

Related errors


AI-assisted analysis of vercel/next.js@0ae8c72462 (2026-08-06). Data as JSON: /api/errors/6a5e142c80b501ea. Report an issue: GitHub.