vercel / next.js

The React Framework
https://nextjs.org
MIT License
123.05k stars 26.29k forks source link

Cannot create app router localized sitemap #67005

Open arvinpoddar opened 3 weeks ago

arvinpoddar commented 3 weeks ago

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/elastic-wave-5d4hkj?workspaceId=b7d16bab-058a-4b6f-b4f8-cb3182273009

To Reproduce

  1. Create a new Next.js app with npx create-next-app@latest (accept all the default settings)
  2. Create a new app/sitemap.ts file
  3. Copy and paste the example from: https://nextjs.org/docs/app/api-reference/file-conventions/metadata/sitemap#generating-a-sitemap-using-code-js-ts. This will work when you visit localhost:3000/sitemap.xml
  4. Now, copy and paste the localized example: https://nextjs.org/docs/app/api-reference/file-conventions/metadata/sitemap#generate-a-localized-sitemap. This will not work. Remove all the alternates, and it works again.

Current vs. Expected behavior

We would expect to see a sitemap with localized alternates when we visit localhost:3000/sitemap.xml. Instead, visiting this route results in a plain text result, with a Uncaught TypeError: Cannot read properties of null (reading 'childNodes') error in the browser console.

CleanShot 2024-06-18 at 21 40 33

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Sun Aug  6 20:05:33 UTC 2023
  Available memory (MB): 4102
  Available CPU cores: 2
Binaries:
  Node: 20.9.0
  npm: 9.8.1
  Yarn: 1.22.19
  pnpm: 8.10.2
Relevant Packages:
  next: 15.0.0-canary.37 // Latest available version is detected (15.0.0-canary.37).
  eslint-config-next: N/A
  react: 19.0.0-rc-6f23540c7d-20240528
  react-dom: 19.0.0-rc-6f23540c7d-20240528
  typescript: 5.3.3
Next.js Config:
  output: N/A

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

Metadata

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

next dev (local)

Additional context

This issue is a duplicate of: https://github.com/vercel/next.js/issues/65817

jerico-wf commented 2 weeks ago

I'm facing the same problem too. However when inspecting the network response, the XML looks valid

image

and running the sitemap.xml link to a sitemp checker like https://www.mysitemapgenerator.com/service/check.html, it passes

Not an expert but I assume this is functionally working, the browser just shows an error displaying the xml

uraden commented 1 day ago

Were you able to resolve this issue? Google search console is not seeing localized versions of the page?