'next-sitemap "Error: Expected ';' on Windows 11

Trying to get a sitemap made for my Next JS site using next-sitemap. From my research, next-sitemap doesn't work on Windows without including cross-env. Any suggestions on what to do?

I currently have my postbuild command set to:

"postbuild": "cross-env next-sitemap --config next-sitemap.js""postbuild": "cross-env next-sitemap --config next-sitemap.js"

And here is my next-sitemap.js:

let policy = {
    userAgent: "*",
};

if (process.env.ENVIRONMENT !== "production") {
    policy.disallow="/";
};

module.exports = {
    siteUrl: process.env.URL,
    generateRobotsTxt: true,
    robotsTxtOptions: {
        policies: [
            policy
        ],
    },
    outDir: "./out"
}

SitemapError



Solution 1:[1]

Tryp running npm run build (or yarn build) first, on this youtube video happened the same to him and he did it like that:

https://www.youtube.com/watch?v=zS-6oiwvNnc

I don't think you need the cross-env, but for windows what you have to do is changing the file name instead. See the docs here.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Marta C