othmane-be
othmane-be

Reputation: 102

Problem with sitemap generation in Gatsby js

I'm having a problem with creating a sitemap for my website. this is gatsby-config.js content :

module.exports = {
  siteMetadata: {
    siteUrl: `https://www.mywebsite.com`,
  },
  plugins: [
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `images`,
        path: `${__dirname}/src/images/`,
      },
    },
    {
      resolve: 'gatsby-plugin-sitemap',
      options: {
        excludes: [],
        query: `
        {
          site {
            siteMetadata {
              siteUrl
            }
          }
          allSitePage {
           nodes {
             path
           }
          }
      }`,
        serialize : ({site,allSitePage}) =>
             allSitePage.nodes.map(node => { // this is line 32
                return {
                  url: `${site.siteMetadata.siteUrl}${node.path}`,
                  changefreq: `never`,
                  priority: 0.5,
                }
              })
          },
    },
    'gatsby-plugin-react-helmet',
    `gatsby-plugin-image`,
    `gatsby-plugin-sharp`,
  ],
}
I get this error when I want to build the project :

enter image description here

note: when I don't add options like this:

module.exports = {
  siteMetadata: {
    siteUrl: `https://www.mywebsite.com`,
  },
  plugins: [
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `images`,
        path: `${__dirname}/src/images/`,
      },
    },
    'gatsby-plugin-sitemap',
    'gatsby-plugin-react-helmet',
    `gatsby-plugin-image`,
    `gatsby-plugin-sharp`,
  ],
}

everything works fine but it does not meet my needs (all pages have the same priority 0.7)


Solved! this code does not work with versions above 3.3.0 so I downgraded the sitemap plugin from 4.9.0 to 3.3.0 and now works like a charm.

Upvotes: 0

Views: 958

Answers (1)

Ferran Buireu
Ferran Buireu

Reputation: 29305

For those who may be facing the issue: It as been solved by downgrading the plugin to the 3.3.0 version prior to the 4.9.0 (the one causing the issue).

https://www.npmjs.com/package/gatsby-plugin-sitemap/v/3.3.0

Upvotes: 3

Related Questions