Sitemap not available through Cloudflare Pages

I’ve got a site running through Cloudflare pages which previously ran on netlify. Before moving over, the sitemap file was available at /sitemap.xml, but since moving to Cloudflare pages this file, as well as robots.txt, lead to our 404 page.

I use next.js and have confirmed in the deploy/build log that the command to generate the sitemap and robots file runs, but it is not available when published.

Has anyone else had this problem, or could someone point me in the right direction?

Thank you,

Can you share your project so we can take a look? As long as these files exist in the root of your output directory, they should be accessible via and without issue.

I believe I have found the reason for the sitemap not being available when using next, and it is not due to Cloudflare pages but an issue with next-sitemap not combining well with next export .

The plugin I’m using, [email protected], outputs its sitemap to the public directory. I followed the next documentation for export
and have set my npm build script to next build && next export , and I followed the next-sitemap documentation instructing me to define a postbuild npm command to trigger the sitemap building.

The problem arises because my npm build command runs next export which would copy the sitemap into out , but the sitemap isn’t there yet as it is only created “postbuild”.

The solution is to set the outDir configuration property in sitemap.config.js to out , which is where next export puts its content, or to rename postbuild to generate-sitemap and update the npm build command to next build && npm run generate-sitemap && next export. Do not do both as next export then removes the recently built sitemap.

Thank you for getting back to me so promptly @cherryjimbo, it was during breaking down the project into its bare components to make it ready to share that I figured out the issue. For posterity, I’ve uploaded the repository with non-working code to github and created a branch with it working.

1 Like