Skip to main content

NextJs Error - Your `getServerSideProps` function did not return an object. Did you forget to add a `return`?

 

When a page component makes use getServerSideProps function and does not return a valid props object then this error will be thrown on to the console .

To fix the error make sure to always have a return statement which returns an object {props:{oof:"oof"}}


export async function getServerSideProps() {

//anyValidData can be number , string , boolean , array , objects & null
// but do not pass undefined
// keep in mind these will be serialized (aka made into valid json )

  return {
    props: { yourObjectKey: anyValidData , yourObjectKey2: anyValidData2 }
  }
}

You might also encounter other errors when using the getServerSideProps :

Comments

Topics

Show more