vercel/next.js · error

id property is required for every item returned from generat

Error message

id property is required for every item returned from generateSitemaps

What it means

Thrown at request time (or prerender) inside the generated sitemap-with-generateSitemaps GET handler when iterating the array returned by generateSitemaps() and finding an item whose `id` is null or undefined. Each sitemap chunk must be addressable by id (used to build the route param __metadata_id__), so a missing id is fatal. The check is `item?.id == null`.

Source

Thrown at crates/next-core/src/next_app/metadata/route.rs:299

            const contentType = {content_type}
            const cache_control = {cache_control}
            const fileType = {file_type}

            if (typeof handler !== 'function') {{
                throw new Error('Default export is missing in {resource_path}')
            }}

            export async function GET(_, ctx) {{
                const paramsPromise = ctx.params
                const idPromise = paramsPromise.then(params => params?.__metadata_id__)

                const id = await idPromise
                const hasXmlExtension = id ? id.endsWith('.xml') : false
                const sitemaps = await generateSitemaps()
                let foundId
                for (const item of sitemaps) {{
                    if (item?.id == null) {{
                        throw new Error('id property is required for every item returned from generateSitemaps')
                    }}
                    const baseId = id && hasXmlExtension ? id.slice(0, -4) : undefined
                    if (item.id.toString() === baseId) {{
                        foundId = item.id
                    }}
                }}
                if (foundId == null) {{
                    return new NextResponse('Not Found', {{
                        status: 404,
                    }})
                }}
                
                const targetIdPromise = idPromise.then(id => {{
                    const hasXmlExtension = id ? id.endsWith('.xml') : false
                    return id && hasXmlExtension ? id.slice(0, -4) : undefined
                }})
                const data = await handler({{ id: targetIdPromise }})
                const content = resolveRouteData(data, fileType)

View on GitHub (pinned to 0ae8c72462)

Solutions

  1. Ensure every item in the generateSitemaps return array has a non-null id property.
  2. Map your data source to { id: <value> } objects before returning.
  3. Filter out items with null/undefined ids before returning.

Example fix

// before: app/sitemap.ts
export async function generateSitemaps() {
  return categories.map(c => ({ name: c.slug })) // missing id
}

// after
export async function generateSitemaps() {
  return categories.map(c => ({ id: c.slug }))
}
Defensive patterns

Strategy: validation

Validate before calling

// Validate generateSitemaps output shape before returning
function assertSitemapIds(items: unknown[]): asserts items is { id: string | number }[] {
  for (const item of items) {
    if (item == null || (item as any)?.id == null) {
      throw new Error('Every generateSitemaps item must have a non-null id')
    }
  }
}
export async function generateSitemaps() {
  const items = await fetchIds()
  assertSitemapIds(items)
  return items
}

Type guard

type SitemapItem = { id: string | number }
const hasId = (v: unknown): v is SitemapItem =>
  v != null && typeof (v as any)?.id === 'string' || typeof (v as any)?.id === 'number'

Try / catch

null

Prevention

When it happens

Trigger: generateSitemaps returns an array where some element lacks an id field, has id: null, or returns primitives/objects without id. Returning a non-array or an array of strings also triggers it if the strings are not objects with id.

Common situations: Returning [{ name: 'x' }] instead of [{ id: 'x' }]; fetching ids from a DB where some are null; returning the raw entity list instead of mapping to { id }.

Related errors


AI-assisted analysis of vercel/next.js@0ae8c72462 (2026-08-06). Data as JSON: /api/errors/e311a2d183eeface. Report an issue: GitHub.