401 unauthorized trying to download 404 page

The deployments just started acting up recently, say like a week ago.

NextJS version is 12.1.0.

If I visit an invalid URL on our website, the 404 page isn’t loaded anymore.
A 500 error is logged in the console as well.

Checking the function SSR logs, I see a 401 unauthorized error trying to download the page.

Now it gets weird from here, if I build the same code using the cli, the routes work fine, but all assets aren’t linked properly.

They (JS, CSS, and Images) all start to be returning a 404.

Below is the log from “Function Next.js SSR handler”.

Hi @ezemmuo,

Thanks for reaching out and welcome to Netlify’s Support Forums!

Could you link us to the url of your site or provide the Netlify subdomain of the site (such as example.netlify.app)?

Hi @Melvin,

This is the URL → https://beans-preview-latest.netlify.app

The error trying to load the 404 page:

Also getting this issue using Page Routing on NextJS 13.4.7

Any thoughts?

Hi can you attach a link to your site or provide the site name/id?

Hey @SamO

site name: beans-preview-latest

site id: 75a69a38-2377-4a27-aadc-c7928bf2100f

Were your sites password protected when this happned?

No, they weren’t password protected.

Everything also worked fine even with that enabled.

Coming back to this, this now works as expected.

I can’t say why, I didn’t do anything different, it just started responding as expected.

If anyone has experienced this and actually figured out why, please leave a comment about it. Thank you. :pray:t2:

Hi @Kevinem,

Could you try again?

I check this morning and all seemed okay.

Hey Folks,

Took a bit to figure out what was going on when i reached this issue. The issue appears to be that Nextjs SSR handler function is unable to fetch the generated 404 and 500 pages when the site access controls are set to “basic password”

We were getting the following error in the function logs:

MissingStaticPage [Error]: Failed to load static file for page: /404 Failed to download https://staging.domain.com/404.html: 401 Unauthorized

Seems this may be an issue when enabling password protection before you deploy the custom error pages in Next.js.

A workaround we have found is to disable password protection and load the 404 page. Then re-enable password protection and it seems to work as expected.

Hopefully it’s just a one off bug in current release of the Next.js SSR plugin. :crossed_fingers: this helps someone save time debugging.

1 Like

This was the cause and “solution” for us too. With Netlify’s Basic Password Protection enabled, we got a 500 server error and the same “MIssingStaticPage” error in the logs. After turning off password protection, we could then visit an invalid URL and view our custom 404 page as expected (generated from /pages/404.tsx), as well as on subsequent visits to that same URL after password-protection was re-enabled.