Skip to main content

Server Error getServerSideProps - `undefined` cannot be serialized as JSON. Please use `null` or omit this value.

 

Error: Error serializing `.oof` returned from `getServerSideProps` in "/oof". Reason: `undefined` cannot be serialized as JSON. Please use `null` or omit this value.


Error: Error serializing `.oof` returned from `getServerSideProps` in "/oof". Reason: `undefined` cannot be serialized as JSON. Please use `null` or omit this value.

You got this error while using getServerSideProps . Everything is working but not able to pass the values to props.

Few things to note before proceeding forward:

  • this is a server side error , meaning you have problematic code executed on the server side inside getServerSideProps .
  • current content cannot be serialized as json (aka make it into a valid json format ) . 
  • this could be because of date object , "undefined" , etc.

getServerSideProps-server-error-code
The above screenshot contains getServerSideProps code block which caused the error.
The oof variable was set to "undefined" intentionally to cause the error but you might encounter this error while using url params or other situations .

If you face this error check what data is being passed and if undefined be passed make sure to set it as "null" instead .
set-null-instead-undefined

Read getServerSideProps(context) blog post for code .

If  you have any other data types like date , then try JSON.stringify() and then JSON.parse() it .

Comments

Topics

Show more