Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gabriel-logan opened this issue May 30, 2024 · 13 comments
Labels
bug Issue was opened via the bug report template. Developer Experience Issues related to Next.js logs, Error overlay, etc. Metadata Related to Next.js' Metadata API. Output (export/standalone) Related to the the output option in `next.config.js`.

Comments

@gabriel-logan
Copy link

gabriel-logan commented May 30, 2024

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.

@gabriel-logan gabriel-logan added the bug Issue was opened via the bug report template. label May 30, 2024
@github-actions github-actions bot added Developer Experience Issues related to Next.js logs, Error overlay, etc. Metadata Related to Next.js' Metadata API. Output (export/standalone) Related to the the output option in `next.config.js`. labels May 30, 2024
@gabriel-logan
Copy link
Author

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

@gabriel-logan
Copy link
Author

I'm generating exactly as the documentation says:

Screenshot_20240601_130839_Chrome

@damien-schneider
Copy link

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

@thibault-chausson

This comment has been minimized.

@junaidalphasquad
Copy link

Having same issue with localize sitemap generation

Screenshot 2024-06-06 at 8 52 53 PM

@gabriel-logan
Copy link
Author

Yes, still not solved

@thibault-chausson
Copy link

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.

@gabriel-logan
Copy link
Author

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.

Why is it just texts like in my example and those of my friends above?

@thibault-chausson
Copy link

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.

@thibault-chausson
Copy link

#66574

@gabriel-logan
Copy link
Author

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.

So do you ensure that there will be no problem with search systems like google search etc?

@thibault-chausson
Copy link

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

@trykovyura
Copy link

@thibault-chausson Can you provide root cause of issue?
Because xml is quite strict format and visual part of xml may not diff.
It diff only with alternate attributes generated by nextjs.
And it is not valid to check XML format with sitemap validators without requirements.

Problem

  • Obvious - generate not valid XML format.
  • Sitemap can be txt, but it must name sitemap.txt but it generated under name sitemap.xml

Requirements

Example with alternate

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
    xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"
    xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"
    xmlns:xhtml="http://www.w3.org/1999/xhtml">
  <url>
    <loc>https://www.example.com/english/page.html</loc>
    <!-- Starting with the news extension tags -->
    <news:news>
      <news:publication>
        <news:name>The Example Times</news:name>
        <news:language>en</news:language>
      </news:publication>
      <news:publication_date>2008-12-23</news:publication_date>
      <news:title>Companies A, B in Merger Talks</news:title>
    </news:news>
    <!-- Next we add video extension tags -->
    <video:video>
      <video:thumbnail_loc>https://www.example.com/thumbs/123.jpg</video:thumbnail_loc>
      <video:title>Lizzi is painting the wall</video:title>
      <video:description>
        Gary is watching the paint dry on the wall Lizzi painted.
      </video:description>
      <video:player_loc>
        https://player.example.com/video/987654321
      </video:player_loc>
    </video:video>
    <!-- And finally the xhtml tags for hreflang -->
    <xhtml:link
                rel="alternate"
                hreflang="de"
                href="https://www.example.de/deutsch/page.html"/>
    <xhtml:link
                rel="alternate"
                hreflang="de-ch"
                href="https://www.example.de/schweiz-deutsch/page.html"/>
    <xhtml:link
                rel="alternate"
                hreflang="en"
                href="https://www.example.com/english/page.html"/>
  </url>
<!-- Add more <url> tags -->

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. Developer Experience Issues related to Next.js logs, Error overlay, etc. Metadata Related to Next.js' Metadata API. Output (export/standalone) Related to the the output option in `next.config.js`.
Projects
None yet
Development

No branches or pull requests

5 participants