{"record":{"id":"6a5e142c80b501ea","repo":"vercel/next.js","slug":"error-for-page-page-server-props-export-erro","errorCode":null,"errorMessage":"Error for page ${page}: ${SERVER_PROPS_EXPORT_ERROR}","messagePattern":"Error for page (.+?): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/next/src/export/routes/pages.ts","lineNumber":49,"sourceCode":"  res: MockedResponse,\n  path: string,\n  page: string,\n  query: NextParsedUrlQuery,\n  params: Params | undefined,\n  htmlFilepath: string,\n  htmlFilename: string,\n  pagesDataDir: string,\n  buildExport: boolean,\n  isDynamic: boolean,\n  sharedContext: PagesSharedContext,\n  renderContext: PagesRenderContext,\n  hasOrigQueryValues: boolean,\n  renderOpts: RenderOpts,\n  components: LoadComponentsReturnType,\n  fileWriter: MultiFileWriter\n): Promise<ExportRouteResult | undefined> {\n  if (components.getServerSideProps) {\n    throw new Error(`Error for page ${page}: ${SERVER_PROPS_EXPORT_ERROR}`)\n  }\n\n  // for non-dynamic SSG pages we should have already\n  // prerendered the file\n  if (!buildExport && components.getStaticProps && !isDynamic) {\n    return\n  }\n\n  // Pages router merges page params (e.g. [lang]) with query params\n  // primarily to support them both being accessible on `useRouter().query`.\n  // If we extracted dynamic params from the path, we need to merge them\n  // back into the query object.\n  const searchAndDynamicParams = {\n    ...query,\n    ...params,\n  }\n\n  if (components.getStaticProps && !htmlFilepath.endsWith('.html')) {","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/packages/next/src/export/routes/pages.ts#L31-L67","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Convert getServerSideProps to getStaticProps (with getStaticPaths for dynamic routes) so the page can be prerendered.","If the page must stay server-rendered, remove `output: 'export'` and deploy to a Node/Serverless runtime instead.","Move the dynamic data fetching to the client (useEffect/SWR/React Query) so the page itself is static.","Audit _app.tsx and _document.tsx — getServerSideProps there also triggers this error."],"exampleFix":"// before — pages/dashboard.js\nexport async function getServerSideProps(ctx) {\n  const user = await fetchUser(ctx.req)\n  return { props: { user } }\n}\n// after — switch to static + client fetch, or getStaticProps\nexport async function getStaticProps() {\n  const data = await fetchPublicData()\n  return { props: { data }, revalidate: 60 }\n}","handlingStrategy":"validation","validationCode":"// Pre-build check: no getServerSideProps when output:'export' is set\nimport fs from 'fs'\nimport path from 'path'\nfunction assertNoGSSPForExport(pagesDir: string, outputMode?: string) {\n  if (outputMode !== 'export') return\n  for (const f of fs.readdirSync(pagesDir)) {\n    const src = fs.readFileSync(path.join(pagesDir, f), 'utf8')\n    if (/getServerSideProps/.test(src)) {\n      throw new Error(`${f} uses getServerSideProps — incompatible with output:'export'`)\n    }\n  }\n}","typeGuard":"function isStaticPage(mod: any): boolean {\n  return !mod.getServerSideProps && (mod.getStaticProps || !mod.getInitialProps)\n}","tryCatchPattern":"// Build-time only; catch in CI:\ntry {\n  await exec('next build')\n} catch (e) {\n  if (/can not be exported/.test(e.message)) {\n    console.error('A page exports getServerSideProps — convert to getStaticProps or drop output:export')\n  }\n  throw e\n}","preventionTips":["Decide upfront whether a page is SSG or SSR; do not mix getServerSideProps with output:'export'.","Run a pre-build grep for getServerSideProps when output:'export' is enabled.","Centralize data fetching so converting SSR→SSG is a one-file change.","Document in AGENTS.md which pages are allowed to be dynamic."],"tags":["static-export","pages-router","ssr","build"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}