Closed hiphop101 closed 4 years ago
Hi @hiphop101
Please give more details to reproduce your issue.
Hi Nico,
if you notice that the sitemap generated does not have
<?xml version="1.0" encoding="UTF-8"?>
without details about your config and the nuxt mode (spa? generate?) I cannot reproduce...
Please at least share your nuxt version, your sitemap module version and your nuxt config.
Sure. here are my package.json should all be latest as I created this project last weekend.
"scripts": { "dev": "nuxt", "build": "nuxt build", "start": "nuxt start", "generate": "nuxt generate", "lint:js": "eslint --ext .js,.vue --ignore-path .gitignore .", "lint": "yarn lint:js" }, "dependencies": { "@nuxt/content": "^1.3.2", "@nuxtjs/axios": "^5.11.0", "@nuxtjs/sitemap": "^2.3.2", "apexcharts": "^3.19.2", "d3": "^5.16.0", "nuxt": "^2.13.0", "nuxt-buefy": "^0.3.31" }, "devDependencies": { "@nuxtjs/eslint-config": "^3.0.0", "@nuxtjs/eslint-module": "^2.0.0", "@nuxtjs/google-analytics": "^2.3.0", "babel-eslint": "^10.1.0", "eslint": "^7.2.0", "eslint-config-prettier": "^6.11.0", "eslint-plugin-nuxt": "^1.0.0", "eslint-plugin-prettier": "^3.1.4", "prettier": "^2.0.5" }
I need your sitemap config from your nuxt.config.js file
here it is:
sitemap: { hostname: 'my website URL', gzip: true, path: '/sitemap.xml', xmlNs: 'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"' }
Your config seems good on sitemap part. Maybe the sitemap is not well declare in "modules" part. Maybe you call a wrong URL according other nuxt config (eg. with a base url). Create a github repository to share a use case that reproduce your issue.
Without all details to reproduce your issue, I will not help your any more more. Sorry.
I've also got bitten by this bug today.
For what I understand, it only happens when the sitemap is using i18n or when you're injecting a links object for each route.
Because this will generate the tag <xhtml:link rel="alternate" hreflang="xx" href="https://example.com/xx" />
When the xhtml:link tag is generated, the resulting sitemap ends up missing the xml version tag
<?xml version="1.0" encoding="UTF-8"?>
The output becomes this:
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
<url>
<loc>https://example.com/pt</loc>
<lastmod>2022-06-07T17:11:37.986Z</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
<xhtml:link rel="alternate" hreflang="en" href="https://example.com/en" />
<xhtml:link rel="alternate" hreflang="pt" href="https://example.com/pt" />
</url>
<url>
<loc>https://example.com/en</loc>
<lastmod>2022-06-07T17:11:37.986Z</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
<xhtml:link rel="alternate" hreflang="en" href="https://example.com/en" />
<xhtml:link rel="alternate" hreflang="pt" href="https://example.com/pt" />
</url>
</urlset>
when it should have been like this:
<?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:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
<url>
<loc>https://example.com/pt</loc>
<lastmod>2022-06-07T17:11:37.986Z</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
<xhtml:link rel="alternate" hreflang="en" href="https://example.com/en" />
<xhtml:link rel="alternate" hreflang="pt" href="https://example.com/pt" />
</url>
<url>
<loc>https://example.com/en</loc>
<lastmod>2022-06-07T17:11:37.986Z</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
<xhtml:link rel="alternate" hreflang="en" href="https://example.com/en" />
<xhtml:link rel="alternate" hreflang="pt" href="https://example.com/pt" />
</url>
</urlset>
After a bit of digging, it seems the bug comes from the sitemap.js library itself. At least, its what this issue makes me think.
If possible, please reopen the issue.
The generated XML does not have xml tag. Google search console does not recognize it.
<?xml version="1.0" encoding="UTF-8"?> is missing