next.js: Sitemap is being generated incorrectly and an error in development also appears when I try to access /sitemap.xml

Link to the code that reproduces this issue

https://github.com/gabriel-logan/multiform-validator/blob/main/docs/src/app/NOTWORKING_sitemap_copy.ts

https://github.com/gabriel-logan/gabriel-logan/blob/main/docs/src/app/sitemap.ts

To Reproduce

As I said, in development mode, the sitemap gives the following error when I try to access the MY_URL/sitemap.xml route:

image

And the second problem is that in the production version where the sitemap is generated, it is being generated incorrectly, when I had few routes registered there, it generated ok, but now that there are a lot of routes it is getting buggy.

Showing the print below

https://multiform-validator.3utilities.com/sitemap.xml image

Current vs. Expected behavior

I was hoping to be able to access it via /sitemap.xml because I’m not using dynamic routes and on my production site I was expecting it to be correct and it’s being wrong.

Provide environment information

OS: Windows, 64bit

PS D:\programas\validadores\multiform-validator\docs> yarn -v
1.22.19
PS D:\programas\validadores\multiform-validator\docs> npm -v
10.8.0
PS D:\programas\validadores\multiform-validator\docs> node -v
v20.12.0
PS D:\programas\validadores\multiform-validator\docs>

  "dependencies": {
    "next": "14.2.3",
    "next-international": "^1.2.4",
    "react": "^18",
    "react-dom": "^18",
    "react-icons": "^5.2.0",
    "react-modern-drawer": "^1.3.1",
    "react-syntax-highlighter": "^15.5.0"
  },

nextconfig

/** @type {import('next').NextConfig} */
const nextConfig = {
	images: {
		unoptimized: true,
		remotePatterns: [
			{
				protocol: "https",
				hostname: "img.shields.io",
				port: "",
				pathname: "**",
			},
			{
				protocol: "https",
				hostname: "badge.fury.io",
				port: "",
				pathname: "**",
			},
			{
				protocol: "https",
				hostname: "cdn.buymeacoffee.com",
				port: "",
				pathname: "**",
			},
		],
	},
	output: "export",
};

export default nextConfig;

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

Not sure, Developer Experience, Metadata, Output (export/standalone)

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

next dev (local), Other (Deployed)

Additional context

I looked for my case in several places and couldn’t find it.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 15 (1 by maintainers)

Most upvoted comments

The sitemap works. You need to go to your sitemap at localhost:3000/sitemap.xml, right-click to save the page, and open it in a text editor. Alternatively, you can check it in your browser’s console.

Having same issue with localize sitemap generation

Screenshot 2024-06-06 at 8 52 53 PM

You can check if the sitemap is valid using the Google console or with a site like this : https://www.xml-sitemaps.com/validate-xml-sitemap.html

It’s just text in the browser because web browsers do not necessarily handle XML correctly, but you can test it with sitemap validators available online.

+1 Exactly the same issue (I’ve tried with different versions of NextJS but same result)

I changed my multiform-validator page to work with ssr, in development mode the error no longer appears, in production a completely wrong sitemap is still generated.

Now I still have a page with the same error that can be put in place for this issue, where the error occurs in dev mode AND in the generation of the sitemap

the new page below:

https://gabriellogan.ddns.net/sitemap.xml

https://github.com/gabriel-logan/gabriel-logan/blob/main/docs/src/app/sitemap.ts

And the multiform-validator is running as ssr and the sitemap is still generated incorrectly: https://multiformvalidator.vercel.app/sitemap.xml