Skip to content

Generating localized sitemap fails with TypeError: Cannot read properties of null (reading 'childNodes') #65817

@chrisalat

Description

@chrisalat

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/mystifying-newton-42cjqp?file=%2Fapp%2Fsitemap.ts

To Reproduce

  1. Use the example from documentation
import type { MetadataRoute } from 'next'
 
export default function sitemap(): MetadataRoute.Sitemap {
  return [
    {
      url: 'https://acme.com',
      lastModified: new Date(),
      alternates: {
        languages: {
          es: 'https://acme.com/es',
          de: 'https://acme.com/de',
        },
      },
    },
    {
      url: 'https://acme.com/about',
      lastModified: new Date(),
      alternates: {
        languages: {
          es: 'https://acme.com/es/about',
          de: 'https://acme.com/de/about',
        },
      },
    },
    {
      url: 'https://acme.com/blog',
      lastModified: new Date(),
      alternates: {
        languages: {
          es: 'https://acme.com/es/blog',
          de: 'https://acme.com/de/blog',
        },
      },
    },
  ]
}
  1. yarn next dev
  2. Browser console throws Uncaught TypeError: Cannot read properties of null (reading 'childNodes')

Current vs. Expected behavior

The sitemap.xml should normally render correctly, but it renders plain text:
https://acme.com 2024-05-15T20:48:04.146Z https://acme.com/about 2024-05-15T20:48:04.146Z https://acme.com/blog 2024-05-15T20:48:04.146Z. The error happens only if I set the alternates attribute! Without alternates it work's like a charm.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.2.0
  Available memory (MB): 16384
  Available CPU cores: 10
Binaries:
  Node: 18.19.0
  npm: 10.2.3
  Yarn: 1.22.19
  pnpm: N/A
Relevant Packages:
  next: 14.2.3
  eslint-config-next: 14.2.3
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.4.5
Next.js Config:
  output: standalone

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

Metadata

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

next dev (local)

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    MetadataRelated to Next.js' Metadata API.bugIssue was opened via the bug report template.invalid linkThe issue was auto-closed due to a missing/invalid reproduction link. A new issue should be opened.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions