Skip to content

Instantly share code, notes, and snippets.

@magnusdahlstrand
Created May 17, 2022 15:25
Show Gist options
  • Save magnusdahlstrand/203d36a855a68a9c8d2849cb6da91247 to your computer and use it in GitHub Desktop.
Save magnusdahlstrand/203d36a855a68a9c8d2849cb6da91247 to your computer and use it in GitHub Desktop.

This repository highlights an issue combining next-sitemap with next export when hosting on a static host.

See the thread which prompted this repo

Setup next-sitemap@2.5.20, 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.

Problem The problem arises because the 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".

Solution The solution is to set the outDir configuration property in sitemap.config.js to out, which is where next export puts its content. Alternatively, rename postbuild to generate-sitemap and update the npm build command to next build && npm run generate-sitemap && next export.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment