nextjs - 💡(How to fix) Fix Turbopack build fails 'Failed to collect page data' on CMS-fed sitemap.xml (works with --webpack) [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#93144Fetched 2026-04-23 07:21:46
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Author
Participants

In Next 16.2.3, when running next build (default Turbopack build) on a project that has app/sitemap.ts (and app/rss.xml/route.ts, app/llms.txt/route.ts) which fetch data from an external CMS (Sanity), the build fails while collecting page data:

Error: Failed to collect page data for /sitemap.xml
    at instantiateRuntimeModule (.next/server/chunks/[turbopack]_runtime.js:882:12)
    at getOrInstantiateRuntimeModule (.next/server/chunks/[turbopack]_runtime.js:895:12)

Interestingly, the same build succeeds when running via vercel build --prod on the Vercel build runner (identical Next version), and also succeeds locally when you pass next build --webpack explicitly.

So the bug appears to be specific to the local Turbopack build pipeline when the project also consumes @xyflow/react, framer-motion, and a CMS-fed sitemap.

Error Message

Error: Failed to collect page data for /sitemap.xml at instantiateRuntimeModule (.next/server/chunks/[turbopack]_runtime.js:882:12) at getOrInstantiateRuntimeModule (.next/server/chunks/[turbopack]_runtime.js:895:12)

Root Cause

In Next 16.2.3, when running next build (default Turbopack build) on a project that has app/sitemap.ts (and app/rss.xml/route.ts, app/llms.txt/route.ts) which fetch data from an external CMS (Sanity), the build fails while collecting page data:

Error: Failed to collect page data for /sitemap.xml
    at instantiateRuntimeModule (.next/server/chunks/[turbopack]_runtime.js:882:12)
    at getOrInstantiateRuntimeModule (.next/server/chunks/[turbopack]_runtime.js:895:12)

Interestingly, the same build succeeds when running via vercel build --prod on the Vercel build runner (identical Next version), and also succeeds locally when you pass next build --webpack explicitly.

So the bug appears to be specific to the local Turbopack build pipeline when the project also consumes @xyflow/react, framer-motion, and a CMS-fed sitemap.

Fix Action

Workaround

Use next build --webpack in package.json scripts. Local build succeeds in ~25s.

Code Example

Error: Failed to collect page data for /sitemap.xml
    at instantiateRuntimeModule (.next/server/chunks/[turbopack]_runtime.js:882:12)
    at getOrInstantiateRuntimeModule (.next/server/chunks/[turbopack]_runtime.js:895:12)
RAW_BUFFERClick to expand / collapse

Description

In Next 16.2.3, when running next build (default Turbopack build) on a project that has app/sitemap.ts (and app/rss.xml/route.ts, app/llms.txt/route.ts) which fetch data from an external CMS (Sanity), the build fails while collecting page data:

Error: Failed to collect page data for /sitemap.xml
    at instantiateRuntimeModule (.next/server/chunks/[turbopack]_runtime.js:882:12)
    at getOrInstantiateRuntimeModule (.next/server/chunks/[turbopack]_runtime.js:895:12)

Interestingly, the same build succeeds when running via vercel build --prod on the Vercel build runner (identical Next version), and also succeeds locally when you pass next build --webpack explicitly.

So the bug appears to be specific to the local Turbopack build pipeline when the project also consumes @xyflow/react, framer-motion, and a CMS-fed sitemap.

Expected behavior

next build with default Turbopack should produce the same output as next build --webpack, and the static sitemap should be generated successfully.

Actual behavior

Build fails at the "collecting page data" stage for /sitemap.xml. The error stack points to Turbopack's runtime module loader.

Workaround

Use next build --webpack in package.json scripts. Local build succeeds in ~25s.

Environment

  • Next.js: 16.2.3
  • React: 19.2.4
  • Node: 20.x (Windows 10 and Vercel's Linux runner)
  • OS: Windows 10 (also reproduced intermittently on Vercel's Ubuntu build runner)

Relevant dependencies

About app/sitemap.ts (essential — could not isolate a minimal repro yet)

Fetches all posts + courses from Sanity via the next-sanity client and returns an array of URLs. Nothing exotic.

Related

Couldn't find an exact duplicate after searching for "Turbopack sitemap collect page data". Closest ones:

  • #68667 — robots.txt generation issue (different cause)
  • #80194 — env vars in standalone output (different)

extent analysis

TL;DR

The most likely fix is to use the next build --webpack command instead of the default Turbopack build to successfully generate the static sitemap.

Guidance

  • The issue appears to be specific to the local Turbopack build pipeline, so using next build --webpack is a reliable workaround.
  • Verify that the next-sanity client is properly configured and fetching data correctly from the Sanity CMS.
  • Check the app/sitemap.ts file for any potential issues that might be causing the build to fail, such as incorrect data handling or formatting.
  • Consider updating dependencies, especially @xyflow/react and framer-motion, to ensure compatibility with Next.js 16.2.3.

Example

No specific code snippet is provided, but ensuring the app/sitemap.ts file is correctly implemented, such as:

import { client } from '../sanity-client';

export default async function getSitemap() {
  const posts = await client.fetch(/* query */);
  const courses = await client.fetch(/* query */);
  // Return an array of URLs
}

is essential for the build process.

Notes

The issue might be related to the interaction between Turbopack and the next-sanity client or other dependencies. Further investigation is needed to determine the root cause.

Recommendation

Apply the workaround by using next build --webpack in package.json scripts, as it has been proven to work locally and does not introduce significant changes to the build process.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

next build with default Turbopack should produce the same output as next build --webpack, and the static sitemap should be generated successfully.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING