javascriptreactjsnext.jsgetstaticprops

Why is my NextJS function 'getStaticProps' not running?


The main reason I'm using Next is the 'getStaticProps' function and it's not even running.

I tried to create a new app from scratch "npx create-next-app@latest" not working, I tried "npx create-next-app" without the "@latest" still doesn't work.

Here's how I tried to test it and didn't even return anything or console.log anything:

export async function getStaticProps() {
  return {
    props: {
      name: 'John' 
    }
  }
}

function Home({ name }) {
  return <h1>Hellos {name}!</h1> 
}

export default Home

There, when I run npm run dev it only returns: "Hellos !" and it doesn't console.log anything, I hope it's just me and the solution is simple.

On the other app I created I ran 'npm run build' and then 'npm start', still the same problem.


Solution

  • getStaticProps only works in the pages router. The new app router uses React server components (rsc).

    Move your page files from app/ to pages/ or start using rsc instead.