NextJS incorrectly returning 500 error for 404 pages only on production

Hello hello :wave:

We are running an SSG website with NextJS at and having some issues with 404 pages on production and preview URLs.

If I try and access it shows me an error 500 instead of a 404, and that is harming our SEO.

When running the exact same project on localhost, be it in development mode or on a locally built and served project, I always get the 404 error correctly.

I’ve tried removing redirect rules and workflows but it didn’t work. It is also crazy hard to debug that kind of error.

Does anybody have a hunch on why that might be happening? I wonder if it can be something related to Netlify’s NextJS plugin, I haven’t tested disabling it yet :thinking:

Update: disabling the NextJS plugin didn’t solve it :frowning:

1 Like

Hey there, @vtrpldn :wave:

Apologies for the delay here.

On your first link,, I am not getting any 404s or errors. Below is a screenshot of what I see when I open your link.

I am seeing a 404 when I follow the second link you share,, which is the expected error based on what you state above.

Are you still encountering this issue? If so, can you please share your project repository?

Hey @hillary!

No worries, I’ve actually got to fix it after I found out a way to debug the then 500 server errors.

Turns out that it was just a matter of checking the ___netlify-odb-handler logs on our project’s functions. Our API was trying to fetch content based on the slug and throwing when it couldn’t find a document with “somegibberish” as slug :sweat_smile:.

1 Like

Hey there, @vtrpldn :wave:

Thanks so much for coming back and letting us know! Glad you found a solution. Happy building :rocket: