Fixing "Sitemap Couldn’t Fetch" Error in Next.js on Vercel

Fixing "Sitemap Couldn’t Fetch" Error in Next.js on Vercel
If you’ve landed here, you’re probably scratching your head over the frustrating “Sitemap Couldn’t Fetch” error in Google Search Console for your Next.js app. Trust me, I’ve been there! I recently faced this issue while deploying my site on Vercel, and after some trial and error, I finally resolved it. In this blog, I’ll share my personal experience, the steps I took to fix it, and some additional tips to help you get your sitemap working smoothly. Let’s dive in!
Understanding the Problem
When Google Search Console throws the “Sitemap Couldn’t Fetch” error, it means Googlebot couldn’t access or retrieve your sitemap file. This can happen for various reasons — incorrect file setup, server issues, or even a typo in your configuration. For me, it was a mix of small oversights that I’ll break down below. Whether you’re using a sitemap.ts file in Next.js or hosting on Vercel like I did, this guide will help you troubleshoot and fix the issue.
My Setup
Before we get into the solution, here’s a quick rundown of my setup:
- Sitemap File: I used a sitemap.ts file to dynamically generate my sitemap in Next.js.
- Robots File: I had a robots.ts file to control crawler access.
- Hosting: My app was deployed on Vercel.
- Sitemap Visibility: Yes, my sitemap was visible in the browser (e.g., https://jigsdev.vercel.app/sitemap.xml), but Google still couldn’t fetch it.
If this sounds familiar, keep reading — I’ve got you covered!
How I Fixed “Sitemap Couldn’t Fetch” in Next.js
Here’s a step-by-step account of what I did to resolve the issue, based on my experience and some research I did along the way.
1. Double-Check the Last-Modified Date Format
I started by digging into Google’s official documentation on sitemaps. One key takeaway? The lastmod
(last modified) date in your sitemap must be in a proper format — like YYYY-MM-DD
or the full ISO 8601 format (e.g., 2025–03–08T12:00:00Z
). Google won’t reject your sitemap for missing priority
or changefreq
(those are optional now), but a malformed lastmod
can cause issues.
In my sitemap.ts
, I initially had dates in a weird format. Here’s how I fixed it:
const siteUrl = "https://jigsdev.vercel.app/"; export default async function sitemap() { return [ { url: `${siteUrl}/`, lastModified: new Date().toISOString().split("T")[0], // Proper YYYY-MM-DD format }, { url: `${siteUrl}/blogs`, lastModified: "2025-03-01", }, ]; }
Tip: If your site is dynamic, fetch the actual last-modified dates from your CMS or database to keep it accurate.
2. Update the Robots.txt File
Next, I reviewed my robots.ts
file. I realized some pages — like my /dashboard
— didn’t need to be indexed by Google. So, I explicitly disallowed them to avoid confusion. Here’s a simplified version of what I used:
export default function robots() { return { rules: { userAgent: "*", allow: "/", disallow: "/dashboard", }, sitemap: "https://jigsdev.vercel.app/sitemap.xml", }; }
Make sure your sitemap URL is correctly listed in the robots.txt
file — it helps Google find it faster.
3. Add Canonical Tags and Metadata
To ensure Google understood my page structure, I added canonical tags and metadata to every page. This isn’t directly tied to the sitemap fetch issue, but it helps with crawlability. In Next.js, you can do this in your page.tsx
files like so:
export const metadata = { title: "My Page Title", alternates: { canonical: "https://jigsdev.vercel.app/my-page", }, };
This step was more of a precaution, but it’s a good practice for SEO anyway.
4. Fix That Sneaky Route Typo
Here’s where I had my “aha!” moment. While reviewing my sitemap.ts
, I noticed I’d mistyped one of my routes. I had mysite/blog-details/[slug]
instead of mysite/blog/[slug]
. A small typo, but it was enough to throw Google off! After fixing it, I resubmitted my sitemap in Search Console.
5. Be Patient After Resubmission
Once I made these changes, I redeployed my app on Vercel and resubmitted the sitemap via Google Search Console (under “Sitemaps” > “Add a new sitemap”). It didn’t fix instantly — Google took about 8–9 hours to re-crawl and process it. So, if your fix doesn’t reflect immediately, give it some time!
Additional Tips to Avoid This Issue
From my research and experience, here are a few extra pointers:
- Test Your Sitemap: Open
yoursite.com/sitemap.xml
in a browser. If it loads without errors, you’re on the right track. - Check Vercel Logs: If the sitemap isn’t generating, peek at your Vercel deployment logs for errors.
- Validate Your Sitemap: Use tools like XML Sitemap Validator to ensure it’s error-free.
- Dynamic Routes: If you have dynamic pages (e.g., blog posts), ensure your
sitemap.ts
fetches them correctly.
Why This Matters for SEO
A working sitemap is crucial for SEO — it tells search engines which pages to crawl and how often. If Google can’t fetch your sitemap, your pages might not get indexed properly, hurting your visibility. Fixing this issue not only resolves the error but also boosts your site’s chances of ranking higher.
Wrapping Up
Fixing the “Sitemap Couldn’t Fetch” error in Next.js took me a bit of detective work, but it boiled down to formatting my lastmod
dates, tweaking my robots.ts
, adding canonical tags, and fixing a silly typo. After redeploying on Vercel and waiting 8–9 hours, Google Search Console gave me the green light.
If you’re facing this issue, start with these steps — they worked for me and should work for you too. Have a different fix or still stuck? Drop a comment below — I’d love to hear your experience!