-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛 BUG: 404 does not work with Vercel #4164
Comments
Actually deeply willing to watch this being resolved, because since I switch from Next.js to Astro, by old blog links is not being shown the 404 page, resulting in Google believing that the URL is still up and not removing them from search results (or at least in the Google Search Console thingy). |
Are you using Vercel Serverless, Edge, or Static? For serverless it should be getting the 404.astro page already: |
I know the OP might just have different setup than me, but I'm also having the same issue and had sent support ticket to Vercel, to which they're "elevating to the team", so here you go. My Astro website's source code is publicly available at https://github.com/intagaming/hxann.com. Here's a random url which doesn't exist, you might try anything after the slash: https://hxann.com/asdCompletelyRandom123aazz. It's completely static, or shall you say Vercel Static. |
@intagaming i cloned your repo and it is producing a 404.html which according to here: https://vercel.com/guides/custom-404-page#static-site-generator-(ssg) that should work. |
Yes, it is, but only locally for me. Have you tried deploying to Vercel? I don't know what it is but you can see the Vercel deployment for yourself in each commit, and it's just not working. I can provide the build inspection should you desire. |
If you have a link you can send me I can take a quick look. |
I included the Build log and the Output thing to the comments of this commit, don't know if it helps or not: intagaming/hxann.com@c77886e |
I'm gonna make a wild guess that it might have something to do with the Vercel router. But again, it should not act like this at all for a Next.js static site, based on my experience with it. |
@intagaming from your screenshot I see a few files named |
That's just an HTML page disguised as a Vercel "file". It's just an Astro page, or specifically a Markdown file in the source code that Astro takes and make an HTML. Here's the content of one. It's the content of Well there's a folder too, which has an |
Ok, that's a bit unusual. I would expect the folders with index.html in them but not those files (with no file extension). I don't think Astro is producing those files. It's probably unrelated to your 404 problem though. The 404.html file exists which according to their docs is all that's needed, so I'm not sure how to further help here. |
I just tried to So... That should make it a bit more interesting to work with. And yeah, locally it looks good. |
Very strange... even if I set the Framework to "other" and provide "dist" as output (where a 404.html sits at root), it doesn't work. Seems to be a problem with Vercel... |
I've created a support ticket at Vercel. Let's see what they will say. |
Thanks @jablonski, please let us know what you find. Will keep the issue open for a little bit in case its a bug on our end. |
Just an update, the Vercel support wrote to me:
My answer after testing:
|
Maybe relevant: I'm using Astro with an /api-folder for Vercel functions. |
Thanks @jablonski, so it sounds like maybe there is something wrong with our SSR output, I'll play around with it. |
I can confirm that Going to dig into the SSR issue as that is likely Astro's bug. |
Awesome |
I'm getting the 404.astro page: https://vercel-404-matthew6.vercel.app/testing However we are getting the wrong status code, so let me try and fix that. |
@matthewp Hi. I don't think the problem is resolved yet. So the Astro Docs' guide to deploy to Vercel literally says that you can skip the Vercel configuration in Astro completely if you don't use SSR. The "Just the basics" template of Astro doesn't use SSR. Indeed it is not fixed as of |
Yep, @intagaming, I'm aware that the 404.html is not working on Vercel. This issue is about the SSR adapter case, and that has been fixed by the linked PR. As you noted you have a support ticket in with Vercel on their 404.html support, there's nothing we can do on our end to fix that problem. |
My interpretation of the problem: when Vercel detects an Astro project (regardless if there's a Vercel adapter installed or not), it runs it in some kind of SSR mode. This works fine with the Vercel adapter, but leads to the 404 problem without the adapter. This problem occurs even if one selects "Other" as framework. So the bug is on the Vercel side (at least for framework = "other" Vercel should just deliver the dist folder). Contacting the Vercel support didn't help. |
routes didn't work for me because I need rewrite rules. Rewrites are not allowed to mix with routes. So I've tested and found this combination (with an example rewrite). And it works!!!!
|
I've added a PR for the docs, so others won't run into this issue: |
There is still an issue with custom 404 pages on Vercel with dynamic routes: #4635 |
Hello, how to get a 404 on Vercel? This issue is reproducible in the official demo: https://vercel.com/templates/astro/astro-edge-functions Edit: I just noticed that there is a remark in the documentation regarding this issue. https://docs.astro.build/en/guides/deploy/vercel/#static-site {
"cleanUrls": true,
} |
Hey guys, this worked for me using Astro and Vercel edge adapter in vercel.json at root (Locally it won't work): {
"cleanUrls": false,
"rewrites": [
{
"source": "(.*)",
"destination": "404.html"
}
]
} If you want the api routes to work using POST then use this: {
"routes": [{ "handle": "filesystem" }, { "src": "/(.*)", "status": 404, "methods": ["GET"], "dest": "/404.html" }]
} |
So is this still an issue? I have been trying to get a working 404 page in Astro with no joy so far... |
Yes @colinmcdermott , I get blank page in Safari and 404 message in Chrome, but no html page. I manage to fix it by creating "[...any].astro" in Pages folder replacing 404.astro. // [...any].astro
|
@cerpow that seems like a better workaround than the routes config ... |
Does it return 404? Without a valid 404 status, it could have consequences on SEO. |
Thank you kindly for the response @cerpow and all. Would also be very interested to know if your work around responds with a 404 status, as it looks great otherwise. A catch 22... ugly 404, or pretty 200... would have to go with the ugly 404 I guess. |
@jtomek @colinmcdermott Hello, no problem! The work around responds with 200 by default but you can set any response status by using @benadam11 Yes, using routes will mess up the POST or any other api routes [...any].astro
|
If like me you are using hybrid rendering and have your configs like this: output: "server", adapter: vercel() You need to remove the export const prerender = true; from your 404 page. I render all my pages statically but still use an API and the 404 page need to be server rendered too. |
I just ran into the same issue using hybrid mode in Astro 3 using Vercel Adapter: the custom 404 page was not being generated. I got it fixed by rendering the 404 page, thanks for the tip! export const prerender = false; |
What version of
astro
are you using?1.0.0-rc.6
Are you using an SSR adapter? If so, which one?
Vercel
What package manager are you using?
npm
What operating system are you using?
Linux
Describe the Bug
Adding a 404.astro to src/pages works fine in Netlify, but in Vercel the 404 is not displayad. It displays the start page with a 200 status code.
Link to Minimal Reproducible Example
Problem is only visible in Vercel
Participation
The text was updated successfully, but these errors were encountered: