In this tutorial, you will learn how to get Next-Sitemap working on a Windows PC. The issue with getting next-sitemap to work on Windows is due to next-sitemap.js. next-sitemap requires this config file to exist under your project root directory, otherwise, it will be thrown an error ❌

The issue with getting this package working on Windows is that Node on Windows works differently than a MAC. On Windows, Node prioritizes local folders over filenames. In the postscript command, instead of loading next-sitemap.js, Node on Windows see a folder in the node_modules folder called next-sitemap and it will try to load the folder. Node ignores the .js part, prioritises folders first, so an error is thrown 😞

To fix this issue you can install an NPM package called cross-env. As Windows does not set environment variables the same as BASH. cross-env will allow a developer to define a single command within package.json that works on both MAC and Windows. You can install cross-env using this command:

Next, you need to update your postbuild script to in package.json:

The scripts section will now look like this:

Running npm run build should now work as expected. Happy Coding 🤘