Nextjs sitemap header error

I am generating my sitemap using this package: https://github.com/iamvishnusankar/next-sitemap I have following:
const setHeader = async (context: GetServerSidePropsContext, chunk: { loc: string }[]) => {
// cache it for 1 day
context.res.setHeader('Cache-Control', 's-maxage=86400, stale-while-revalidate');
context.res.setHeader('Content-Type', 'text/xml');

const sitemaps = await getServerSideSitemap(context, chunk);

context.res.write(sitemaps);
context.res.end();

return { props: {} };
};
const setHeader = async (context: GetServerSidePropsContext, chunk: { loc: string }[]) => {
// cache it for 1 day
context.res.setHeader('Cache-Control', 's-maxage=86400, stale-while-revalidate');
context.res.setHeader('Content-Type', 'text/xml');

const sitemaps = await getServerSideSitemap(context, chunk);

context.res.write(sitemaps);
context.res.end();

return { props: {} };
};
But right now I am getting this error:
error - Error: Cannot set headers after they are sent to the client

code: 'ERR_HTTP_HEADERS_SENT',
page: '/sitemap/[sitemapId]'
error - Error: Cannot set headers after they are sent to the client

code: 'ERR_HTTP_HEADERS_SENT',
page: '/sitemap/[sitemapId]'
GitHub
GitHub - iamvishnusankar/next-sitemap: Sitemap generator for next.j...
Sitemap generator for next.js. Generate sitemap(s) and robots.txt for all static/pre-rendered/dynamic/server-side pages. - GitHub - iamvishnusankar/next-sitemap: Sitemap generator for next.js. Gene...
4 Replies
utdev
utdev•2y ago
Not sure what I am doing wrong, but I actually remember this working a couple of weeks ago 😕
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
utdev
utdev•2y ago
@Folded-Code I think I managed to fix it, what are your issues right now? @Folded-Code You can DM me if you like to later on
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server