getServerSideProps never runs, or its data never reaches the component
getServerSideProps is defined, but the component never receives its dataShort answer
Next.js calls getServerSideProps only when it is exported from a page file in pages/. Exported from a component, a layout or a file in app/, it is ignored. Move it to the page and pass the data down as props, and read its logs in the terminal, not in the browser console.
Fix it fast
1Find out which cause you have
List every file that exports getServerSideProps. Anything outside pages/ is ignored, so a hit in components/ or app/ already explains the symptom.
grep -rln "getServerSideProps" . --include="*.js" --include="*.jsx" --include="*.ts" --include="*.tsx" --exclude-dir=node_modules --exclude-dir=.next2Match what you see, then jump to its fix
- 1
grep finds getServerSideProps in components/, lib/ or a hook file, and pages/ has no such exportThe function is exported from a component, not from a pageFix - 2
The page shows correct data, but nothing from getServerSideProps appears in DevToolsThe log is being looked for in the browserFix - 3
The route is app/.../page.js and an exported getServerSideProps is never calledThe file lives in app/, where the function was replacedFix
- 1
What does the error look like?
getServerSideProps is defined, but the component never receives its dataconsole.log inside getServerSideProps prints nothing in the browser consoleA getServerSideProps export in a file under app/ has no effect
Cause 1 of 3
The function is exported from a component, not from a page
1Check
The docs state that getServerSideProps can only be exported from a page. A page is a file in pages/ whose default export is the page component.
grep -rn "export .*getServerSideProps" components pages2Fix
Move the function into the page file that renders the component, and hand the result to the component as props.
// pages/dashboard.js
import Stats from '../components/Stats'
export async function getServerSideProps() {
const res = await fetch('https://api.example.com/stats')
return { props: { stats: await res.json() } }
}
export default function Dashboard({ stats }) {
return <Stats stats={stats} />
}3Verify
Request the page and look at the returned HTML. The props passed to the page are part of the initial HTML.
curl -s http://localhost:3000/dashboardConfirmed by nextjs.org
Cause 2 of 3
The log is being looked for in the browser
1Check
getServerSideProps runs on the server. On a full load that is the Node.js process behind next dev or next start. On a client-side move through next/link or next/router, the browser asks the server to run it. Either way the output goes to the server's terminal.
export async function getServerSideProps(context) {
console.log('getServerSideProps ran for', context.resolvedUrl)
return { props: {} }
}2Fix
Read the terminal where the server runs. To see the data in the browser, log it inside the page component, since props reach the client as part of the initial HTML.
export default function Dashboard({ stats }) {
console.log('props in the browser', stats)
return null
}3Verify
Reload the page and see the first line in the terminal and the second in the browser console.
npm run devConfirmed by nextjs.org
Cause 3 of 3
The file lives in app/, where the function was replaced
1Check
Inside the app directory, getServerSideProps and getStaticProps are replaced by data fetching in async Server Components.
ls app && grep -rn "getServerSideProps" app2Fix
Delete the export and fetch inside the page component. Setting cache to no-store makes each request fetch fresh data, which is the closest match to the old behaviour.
// app/dashboard/page.js
export default async function Dashboard() {
const res = await fetch('https://api.example.com/stats', { cache: 'no-store' })
const stats = await res.json()
return <pre>{JSON.stringify(stats)}</pre>
}3Verify
Open the route and confirm the data renders without any props argument.
npm run devConfirmed by nextjs.org
How do I stop it coming back?
- Keep one rule in the team: data functions live in page files, and components only receive props.
- Look for server-side logs in the terminal first when a function is meant to run on the server.
- Type the function with satisfies GetServerSideProps, as the Next.js TypeScript example does, so the return shape is checked.
- Pick one router per route. Use pages/ with getServerSideProps, or app/ with async Server Components, and do not mix their data APIs in one file.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Web apps
getStaticProps is ignored or rejected in a Next.js project
How to fetch data server-side in the latest Next.js? Tried getStaticProps but it's not running and getting undefined
getStaticProps belongs to the Pages Router.
4 causes, each with a fixWeb apps
AuthUserPoolException: Auth UserPool not configured in a Next.js app
Auth UserPool not configured
The error means an Amplify Auth call ran before Amplify.configure did.
3 causes, each with a fixWeb apps
Apollo Server rejects a request as a potential CSRF
HTTP 400 Bad Request from the GraphQL endpoint
Apollo Server's CSRF prevention is on by default.
3 causes, each with a fixWeb apps
Clerk cannot read its publishable key in a Next.js app
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY is undefined
Clerk reads NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY.
3 causes, each with a fixWeb apps
The shell cannot find create-next-app
command not found: create-next-app
create-next-app is not meant to be installed as a shell command.
2 causes, each with a fixWeb apps
ESLint fails with: Cannot find module 'next/babel'
ESLint stops on the first file with a Babel or parser error instead of listing lint results
next/babel is a Babel preset that ships inside the next package.
3 causes, each with a fix