Custom Next.js Error Page

We have a Next.js app being hosted on Netlify.

We are trying to create a custom error page which handles non-404 errors and Next.js suggests that we use an _error.js page in the pages/ folder to accomplish this. Locally this error page works when we cause a 500 error. However when it’s deployed to Netlify, causing a 500 error only gives us a JSON response instead of the error page.

We are using this plugin (GitHub - netlify/netlify-plugin-nextjs: A build plugin to integrate Next.js seamlessly with Netlify) to handle server-side rendering.