Next.js Discord

Discord Forum

Invariant Headers on Sitemap.ts

Unanswered
Pfzoz posted this in #help-forum
Open in Discord
Inside my src/app I have a sitemap.ts with generateSitemaps() and sitemap() functions. The problem is that I need access to certain data that is acquired through fetch(), but that fetch needs a parameter which is the site's origin. That origin changes, is dynamic within different unique domains. I try to use next/headers headers() and it works fine until I try to build it on vercel, then I get the following error:
Error: Invariant: headers() expects to have requestAsyncStorage, none available.
    at p (/vercel/path0/.next/server/chunks/975.js:22:1881)
    at v (/vercel/path0/.next/server/app/sitemap/[__metadata_id__]/route.js:1:2768)
    at r (/vercel/path0/.next/server/app/sitemap/[__metadata_id__]/route.js:1:2631)
    at f (/vercel/path0/.next/server/app/sitemap/[__metadata_id__]/route.js:1:2469)

Why is this happening, I saw people telling online to isolate it in different async functions, but that also did not work

0 Replies