debugging sentry: _error.js called with falsy error

Nazreen Mohamad
2 min readAug 28, 2023

This is for those who are using Sentry inside a Next.js app

Hopefully your root cause was the same as mine.

My set up: Next.js app that was deployed via Static Site Generation.

The offender: getInitialProps inside the stock _error.js that Sentry told me to set up.

The solution:

Breakdown:

  • Changing getIntitialProps to getStaticProps since we are not using Server-side Rendering. Also note that, instead of attaching it to the component, we have to export getStaticProps directly from the component file.
  • Nesting the return value in an object and under a props property as this is what getStaticProps expects. Otherwise, it will error.

Also note: getInitialProps is the legacy name, but Next.js has renamed this to getServerSideProps for greater clarity.

If you were curious, this is all that `NextErrorComponent.getInitialProps` does:

It just returns the statusCode. Still, I think it demonstrates the intention more by maintaining the usage of that function, rather than returning manually accessing the statusCode value.

Hope that helped.

--

--