sitemap-module icon indicating copy to clipboard operation
sitemap-module copied to clipboard

/sitemap.xml returning 404 on Vercel

Open Eazash opened this issue 3 years ago • 13 comments

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
    ],
  },

Eazash avatar Sep 30 '21 07:09 Eazash

Hi @Eazash , having the same issue. Were you able to resolve it?

madebyfabian avatar Nov 12 '21 14:11 madebyfabian

@madebyfabian Are you including @nuxt/sitemap in dependencies or devDependencies?

jonathanmelville avatar Nov 12 '21 15:11 jonathanmelville

@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 avatar Nov 12 '21 17:11 madebyfabian

@madebyfabian Yep, it's gotta in be in dependencies or it doesn't work.

jonathanmelville avatar Nov 12 '21 17:11 jonathanmelville

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.

IsraelOrtuno avatar Dec 16 '21 12:12 IsraelOrtuno

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.

lexvzalingen avatar Jan 11 '22 20:01 lexvzalingen

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.

jonathanmelville avatar Jan 11 '22 20:01 jonathanmelville

I did the same as @jonathanmelville. Moved to generate the sitemap at build time.

IsraelOrtuno avatar Jan 11 '22 21:01 IsraelOrtuno

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 avatar Jan 12 '22 18:01 madebyfabian

@madebyfabian thanks a lot! This just works!

IsraelOrtuno avatar Jan 14 '22 12:01 IsraelOrtuno

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.

nachoadjust avatar Dec 21 '22 15:12 nachoadjust

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!

danieldanielecki avatar Mar 07 '23 09:03 danieldanielecki

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?

MickL avatar Apr 01 '24 20:04 MickL