sitemap-module
sitemap-module copied to clipboard
/sitemap.xml returning 404 on Vercel
I am getting a 404 not found error when accessing sitemap.xml for a site deployed on vercel. I get the sitemap in dev mode however. This error only seems to occur in production mode my vercel.json
{
"version": 2,
"builds":[
{
"src": "nuxt.config.js",
"use": "@nuxtjs/vercel-builder",
"config": {
"serverFiles": [
".nuxt/dist/sitemap-routes.json"
]
}
}
]
}
my nuxt.config.js
sitemap: {
hostname: process.env.VERCEL_URL || process.env.NUXT_ENV_VERCEL_URL,
exclude: ['/auth', '/admin', '/admin/**'],
routes: [
//my dynamic routes
],
},
Hi @Eazash , having the same issue. Were you able to resolve it?
@madebyfabian Are you including @nuxt/sitemap
in dependencies
or devDependencies
?
@jonathanmelville Including it in devDependencies currently. After moving it to regular dependencies, it works! Strange, since everyone tells you everything has to be in devDependencies when deploying nuxt ssr to vercel. All this dependency thing with vercel is a pure hell tbh. I also have to install the package "esm" for whatever reason, otherwise the whole serverless process errors.
But yeah, thanks for the tip!
@madebyfabian Yep, it's gotta in be in dependencies
or it doesn't work.
Still no luck, @nuxt/sitemap
in dependences
but sitemap.xml
still gets 404. What's weird is that /sitemap-routes.json
returns an empty object {}
. It does not even include the homepage.
Do you have any dynamic routes @IsraelOrtuno? I have dynamic routes with a custom 404 page in case the dynamic route is not found. That is overriding the sitemap URL in my case, resulting in continuous 404s.
I decided after much frustration that it's easier to just generate sitemaps manually at build time than to try and get this module working.
I did the same as @jonathanmelville. Moved to generate the sitemap at build time.
Hi y'all, if you still having this problem: I was able to get it to work on multiple different nuxt ssr vercel projects. Here is my config:
package.json
{
"dependencies": {
"@nuxtjs/sitemap": "^2.4.0"
}
}
vercel.json
note the internalServer: true
here.
{
"version": 2,
"builds": [
{
"src": "nuxt.config.js",
"use": "@nuxtjs/vercel-builder",
"config": {
"serverFiles": [
"package.json",
"server/**",
".nuxt/dist/sitemap-routes.json"
],
"internalServer": true
}
}
]
}
what also does help is not to have a buildDir: '...'
option in your nuxt.config.js
since this kind of prevents the vercel nuxt builder to access the files in production.
let me know if this does help anybody.
@madebyfabian thanks a lot! This just works!
Do you know if I should see the sitemap xml files listed in Vercel's Source > Output files tree after applying @madebyfabian's answer?
The sitemap urls work for my project, but I believe they are being created on runtime, rather than at build time.
I decided after much frustration that it's easier to just generate sitemaps manually at build time than to try and get this module working.
had the same experience, because instead of yarn generate
I've used yarn build
, after that change everything works onlocalhost
and on deployment (Firebase
in my case). For deployment, I had to manually copy paste sitemap.xml
& sitemap.xml.gz
or adjust a predeploy
script in firebase.json
to make sure those files will be deployed. The same for robots.txt
btw.
Edit: make sure to put those files (robots.txt
and sitemaps) inside public/
, not public/_nuxt
!
Ive place @nuxtjs/sitemap
in dependencies
but my sitemap is not available and I dont see it in the Vercel logs or build output. I dont have a vercel.json
.
Works fine on localhost but nothin on Vercel.
Did anyone make this working?