Production issue with 404 page in pages router

We have a Custom404 page in our pages router that includes a getStaticProps function. This component has been working since forever, but recently it has started to throw the 500 page instead when a dynamic page /[id] with getServerSideProps returns:

{ notFound: true }

The logs show this error in Vercel:
⨯ [Error: Failed to load static file for page: /404 ENOENT: no such file or directory, open ‘/var/task/.next/server/pages/404.html’]

How ever if I go directly to visit my website/404 the page renders properly.

Additionally, looking at the build logs, for some reason I can see that the /404 page has been “(Static) prerendered as static content” instead of “prerendered as static HTML (uses getStaticProps)” like the other 500 page, when they both include getStaticProps, not sure if this has to do with the issue.

I am currently on Next 15.1.0.

There’s another community post with 404 debugging tips that might be helpful. Please give these solutions a try and let us know how it goes.

A human should be around soon to offer more advice. But you can also get helpful information quickly by asking v0.