next.js: sitemap in google search console says "Couldn't fetch"

Discussed in https://github.com/vercel/next.js/discussions/75774

<div type='discussions-op-text'>

Originally posted by CodingReaper1 February 6, 2025

Link to the code that reproduces this issue

https://github.com/CodingReaper1/TheWildOasisAdminNextJs

To Reproduce

you don’t need to reproduce I think

Current vs. Expected behavior

So I have created dynamic sitemap in nextjs which you can isee in my github repo in app folder problem is no matter what I can’t successfully register sitemap on google search console.

I have seen discussion about this in github already https://github.com/vercel/next.js/issues/51649 however it said that I should create new issue.

I have tried everything shown in that github discussion

I went here www.xml-sitemaps.com/validate-xml-sitemap.html to test sitemap no issues there

I tried adding forward / or search queries in case request was cached

Image

I do have middleware I have page “/sitemap.xlm” in public routes then I tried completly disabling middleware on sitemap page but that didn’t work either I have no idea what to do.

Provide environment information

operating system: windows 10
nextjs: 14
react: 18
you can see all packages in repo
live app if that helps somehow: the-wild-oasis-admin-nextjs.vercel.app

Which area(s) are affected? (Select all that apply)

Metadata

Which stage(s) are affected? (Select all that apply)

Vercel (Deployed)

Additional context

No response</div>

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 5
  • Comments: 26 (2 by maintainers)

Most upvoted comments

I found a solution. Just add a slash at the end.

Just update

https:///www.example.com/sitemap.xml

to

https:///www.example.com/sitemap.xml/

Hope this can help.

https://calcly.xyz/sitemap.xml?force=1

Adding a parameter force=1 solved my problem.

I found a solution. Just add a slash at the end.

Just update

https:///www.example.com/sitemap.xml

to

https:///www.example.com/sitemap.xml/

Hope this can help.

This solved for me!

I completely forgot about this issue, because I started working on another project Nothing is changed on me I made some changes, but sitemap should be valid, but is not

Image

I actually uploaded another demo app which is part of the first application, which has same kind of issue? Image

I did fix the issue so I have no idea why is it still showing this 10 errors Image

Maybe it is actually uploaded but it doesn’t show here because of cache?

I attempted all the “fixes” suggested in this issue and many others, but none resolved the problem. For context, I use next-sitemap to generate sitemaps and robots.txt at build time.

I noticed @Joffey say they had success, but also noticed they use a custom domain, so I figured I would try that, and it worked.

So the only solution that worked for me was adding my own custom domain to the deployment and setting up redirects, like so:

https://steamgameidler.vercel.app → 301 redirect → https://steamgameidler.com
https://www.steamgameidler.com → 301 redirect → https://steamgameidler.com
https://steamgameidler.com → Production

After that, I added the custom domain as a property in GSC and successfully submitted the full domain and sitemap route without issues.

When using a vercel.app domain, GSC requires selecting “URL Prefix” instead of “Domain” as the property type. This may limit sitemap submissions because the root domain (vercel.app) is predefined. I don’t know how or why this would be an issue, but it’s my best guess, because other than the redirects, the only differences are:

  • With a vercel.app property, GSC allows only the sitemap route (e.g., /sitemap.xml):
    Image

  • With a custom domain property, you can submit the full domain and route (e.g., https://steamgameidler.com/sitemap.xml):
    Image

I still cannot get the sitemap to work with the vercel.app property. Why? Not a clue. But based on these findings, it seems the issue might be with how vercel.app domains are handled in GSC.

The issue is that Google search console expects a xml file with utf-8 encoded and also cors should not block the request, so just head over to next.config.js and add these headers

async headers() { return [ { source: '/sitemap.xml', headers: [ { key: 'Content-Type', value: 'text/xml; charset=utf-8', }, { key: 'Access-Control-Allow-Origin', value: '*' }, { key: 'Access-Control-Allow-Methods', value: '*' }, { key: 'Access-Control-Allow-Headers', value: '*' } ], }, ]; }

and this should work fine

  1. In vercel go to Project Settings -> Data Cache -> Purge Cache -> Purge Everything.

This likely wouldn’t have been the “fix”. GSC and Googlebot maintain their own independent cache, separate from Vercel’s cache, so purging Vercel’s cache wouldn’t force GSC to fetch a new version from the server.

A better method would be renaming the sitemap file (e.g., sitemap.xml to sitemap2.xml) as GSC will treat this as a completely new resource, bypassing any cached version and forcing Googlebot to fetch the updated sitemap immediately upon submission.

Interesting… I tried every single suggested solution, including changing the sitemap file name, but nothing worked.

I found a solution. Just add a slash at the end.

Just update

https:///www.example.com/sitemap.xml

to

https:///www.example.com/sitemap.xml/

Hope this can help.

Where did u add / if u mean google search console it doesn’t work even after all this time it still says couldn’t fetch This is beyond stupid at this point

I have the same issue with my sitemap.xml how to solve the issue. i tried moving the sitemap.xml to a folder and tried but still same problem

Edit by maintainer bot: Comment was automatically minimized because it was considered unhelpful. (If you think this was by mistake, let us know). Please only comment if it adds context to the issue. If you want to express that you have the same problem, use the upvote 👍 on the issue description or subscribe to the issue for updates. Thanks!

I has a similar issue, when using generateSitemaps @CodingReaper1

The difference is that I had sitemap.ts here: src/app/sitemap.ts. And because of using generateSitemaps() the sitemap was generated at website.com/sitemap/0.xml

Solution was to move sitemap.ts in an inner folder: That is: src/app/sitemaps/sitemap.ts

After this google is able to fetch from website.com/sitemaps/sitemap/0.xml

I think it’s worth trying to move your sitemap.ts to ./sitemaps/sitemap.ts, and try using the new URL location (i.e https://the-wild-oasis-admin-nextjs.vercel.app/sitemaps/sitemap.xml