Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

getStaticProps is ignored or rejected in a Next.js project

Error"getStaticProps" is not a valid Next.js entry export value

Short answer

getStaticProps belongs to the Pages Router. Inside the app directory it is not used, and Next.js rejects it as an entry export. Fetch data directly in an async Server Component instead. If you do stay on pages, export it only from a page file, as a standalone function.

  • Applies to Next.js 15, Next.js 16, TypeScript 5
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check which router the failing file belongs to. Files under app/ use the App Router; files under pages/ use the Pages Router.

    grep -rn "getStaticProps\|getServerSideProps" app pages src 2>/dev/null
  2. 2Match what you see, then jump to its fix

    1. 1The page sits at app/.../page.tsx and the prop you expected arrives as undefined, or the type check names the export as invalid.getStaticProps is exported from a file inside app/Fix
    2. 2getStaticProps lives in pages/ but in a shared component, _app, _document or _error.The function is in a file that is not a pageFix
    3. 3The code reads Page.getStaticProps = ... or similar.getStaticProps is attached as a property of the componentFix
    4. 4getStaticProps runs (you see it in the build) but the page gets empty props.A custom _app drops pagePropsFix

What does the error look like?

  • "getStaticProps" is not a valid Next.js entry export value
  • How to fetch data server-side in the latest Next.js? Tried getStaticProps but it's not running and getting undefined

Cause 1 of 4

getStaticProps is exported from a file inside app/

1Check

In the app directory the old data-fetching functions are replaced by a newer API built on async Server Components.

ls app && grep -n "getStaticProps" app -r

2Fix

Delete the export, make the page an async function and fetch inside it. By default fetch is not cached; use the cache options to get build-time or timed behaviour.

// app/page.tsx
export default async function Page() {
  const res = await fetch('https://api.example.com/items', {
    cache: 'force-cache',
  })
  const items = await res.json()
  return <ul>{items.map((i: { id: string; name: string }) => <li key={i.id}>{i.name}</li>)}</ul>
}

3Verify

Build the project and open the route; the data renders without a props argument.

npx next build

Confirmed by nextjs.org

Did this fix it?

Cause 2 of 4

The function is in a file that is not a page

1Check

It can only be exported from a page. Look at where each export lives.

grep -rln "export .*getStaticProps" pages components

2Fix

Move the function into the page file and pass the data down as props.

// pages/blog.tsx
export async function getStaticProps() {
  const res = await fetch('https://api.example.com/posts')
  const posts = await res.json()
  return { props: { posts } }
}

export default function Blog({ posts }) {
  return <p>{posts.length} posts</p>
}

3Verify

Run the build; the page is prerendered with its props.

npx next build

Confirmed by nextjs.org

Did this fix it?

Cause 3 of 4

getStaticProps is attached as a property of the component

1Check

It must be exported as a standalone function; it does not work as a property of the page component.

grep -rn "\.getStaticProps *=" pages

2Fix

Export it by name from the page module.

export async function getStaticProps() {
  return { props: { ready: true } }
}

3Verify

Restart the dev server; the page now receives the props.

npm run dev

Confirmed by nextjs.org

Did this fix it?

Cause 4 of 4

A custom _app drops pageProps

1Check

With a custom app, the pageProps must be passed to the page component.

cat pages/_app.tsx

2Fix

Spread pageProps onto the page component in _app.

export default function App({ Component, pageProps }) {
  return <Component {...pageProps} />
}

3Verify

Reload the page; the props arrive.

npm run dev

Confirmed by nextjs.org

Did this fix it?

How do I stop it coming back?

  • In the app directory fetch in async Server Components; use fetch cache options in place of getStaticProps and revalidate.
  • Use generateStaticParams in place of getStaticPaths for dynamic routes.
  • Keep a short note in the repo saying which folders use which router.

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

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.