Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'gatsby-plugin-sitemap' doesn't generate a /sitemap.xml file #31095

Closed
mikeyfe6 opened this issue Apr 28, 2021 · 20 comments · Fixed by #31130
Closed

'gatsby-plugin-sitemap' doesn't generate a /sitemap.xml file #31095

mikeyfe6 opened this issue Apr 28, 2021 · 20 comments · Fixed by #31130
Labels
type: bug An issue or pull request relating to a bug in Gatsby

Comments

@mikeyfe6
Copy link

mikeyfe6 commented Apr 28, 2021

Description

'gatsby-plugin-sitemap' doesn't generate a sitemap.xml file, even with default config.

I've changed to the default config of this plugin. In the past it worked like a charm with this code (beneath) but since gatsby-plugin-sitemap v4 it stopped working. Now even the default config doesn't show me the sitemap by going to 'yoursiteurl.com/sitemap.xml'.

{
      resolve: 'gatsby-plugin-sitemap',
      options: {
        query: `
        {
          site {
            siteMetadata {
              siteUrl
            }
          }

          allSitePage {
            edges {
              node {
                path
                context {
                  updatedAt
                }
              }
            }
          }
      }`,
        serialize: ({ site, allSitePage }) =>
          allSitePage.edges.map((edge) => ({
            url: `${site.siteMetadata.siteUrl}${edge.node.path}`,
            changefreq: 'daily',
            priority: 0.7,
            lastmodISO: edge.node.context.updatedAt,
          })),
      },
    },

or

plugins: [`gatsby-plugin-sitemap`]

The old config gives me serializing errors and the second (default) one gives me no sitemap, but goes to 404. What am i doing wrong??

Expected result

Sitemap should show up when I gatsby build && gatsby serve and go to localhost:9000/sitemap.xml ('localhost:9000/sitemap' isn't working either)

Actual result

No sitemap to be found...

Environment


  System:
    OS: macOS 11.3
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 15.14.0 - ~/.nvm/versions/node/v15.14.0/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 7.11.1 - ~/.nvm/versions/node/v15.14.0/bin/npm
  Languages:
    Python: 2.7.16 - /usr/bin/python
  Browsers:
    Chrome: 90.0.4430.93
    Safari: 14.1
  npmPackages:
    gatsby: ^3.4.0 => 3.4.0 
    gatsby-plugin-canonical-urls: ^3.4.0 => 3.4.0 
    gatsby-plugin-catch-links: ^3.4.0 => 3.4.0 
    gatsby-plugin-eslint: ^3.0.0 => 3.0.0 
    gatsby-plugin-feed: ^3.4.0 => 3.4.0 
    gatsby-plugin-google-tagmanager: ^3.4.0 => 3.4.0 
    gatsby-plugin-image: ^1.4.0 => 1.4.0 
    gatsby-plugin-manifest: ^3.4.0 => 3.4.0 
    gatsby-plugin-netlify: ^3.4.0 => 3.4.0 
    gatsby-plugin-nprogress: ^3.4.0 => 3.4.0 
    gatsby-plugin-offline: ^4.4.0 => 4.4.0 
    gatsby-plugin-react-helmet: ^4.4.0 => 4.4.0 
    gatsby-plugin-robots-txt: ^1.5.6 => 1.5.6 
    gatsby-plugin-sass: ^4.4.0 => 4.4.0 
    gatsby-plugin-sharp: ^3.4.0 => 3.4.0 
    gatsby-plugin-sitemap: ^4.0.0 => 4.0.0 
    gatsby-plugin-smoothscroll: ^1.2.0 => 1.2.0 
    gatsby-remark-images: ^5.1.0 => 5.1.0 
    gatsby-remark-images-contentful: ^4.1.0 => 4.1.0 
    gatsby-remark-relative-images: ^2.0.2 => 2.0.2 
    gatsby-source-contentful: ^5.4.0 => 5.4.0 
    gatsby-source-filesystem: ^3.4.0 => 3.4.0 
    gatsby-transformer-remark: ^4.1.0 => 4.1.0 
    gatsby-transformer-sharp: ^3.4.0 => 3.4.0 
  npmGlobalPackages:
    gatsby-cli: 3.4.0
@mikeyfe6 mikeyfe6 added the type: bug An issue or pull request relating to a bug in Gatsby label Apr 28, 2021
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Apr 28, 2021
@mikeyfe6 mikeyfe6 changed the title 'gatsby-plugin-sitemap' doesn't generate /sitemap.xml file 'gatsby-plugin-sitemap' doesn't generate a /sitemap.xml file Apr 28, 2021
@flikteoh
Copy link

I'm also having issue with the sitemap plugin with Error: Page array from `query` wasn't found at `data.allSitePage.nodes`.

@holliepearson
Copy link

I've also experienced this issue after upgrading to 4.0.0. In version 3.3.0 using plugins: ['gatsby-plugin-sitemap'] would generate a sitemap.xml file in the public directory but in 4.0.0 nothing is created and there are no errors.

I also tried the example config from the docs which again returned no errors but did not create a file.

The plugin code appears to run correctly as a console.log inside the example prints out as expected

@flikteoh
Copy link

I've also experienced this issue after upgrading to 4.0.0. In version 3.3.0 using plugins: ['gatsby-plugin-sitemap'] would generate a sitemap.xml file in the public directory but in 4.0.0 nothing is created and there are no errors.

I also tried the example config from the docs which again returned no errors but did not create a file.

The plugin code appears to run correctly as a console.log inside the example prints out as expected

Were you running gatsby develop or gatsby build with no errors?

@holliepearson
Copy link

I've also experienced this issue after upgrading to 4.0.0. In version 3.3.0 using plugins: ['gatsby-plugin-sitemap'] would generate a sitemap.xml file in the public directory but in 4.0.0 nothing is created and there are no errors.
I also tried the example config from the docs which again returned no errors but did not create a file.
The plugin code appears to run correctly as a console.log inside the example prints out as expected

Were you running gatsby develop or gatsby build with no errors?

This is when running gatsby build. Running gatsby clean before does not fix the issue either.

@holliepearson
Copy link

I just tried removing my node_modules and package-lock.json for a fresh install and the problem still persists. 😢

If it's any help i've added my environment below:

  System:
    OS: Windows 10 10.0.19042
    CPU: (6) x64 Intel(R) Core(TM) i5-8400 CPU @ 2.80GHz
  Binaries:
    Node: 15.10.0 - C:\Program Files\nodejs\node.EXE
    npm: 7.11.1 - C:\Program Files\nodejs\npm.CMD
  Languages:
    Python: 3.9.2 - /c/Python39/python
  Browsers:
    Chrome: 90.0.4430.93
    Edge: Spartan (44.19041.423.0), Chromium (90.0.818.49)
  npmPackages:
    gatsby: 3.4.0 => 3.4.0
    gatsby-plugin-gdpr-cookies: ^2.0.0 => 2.0.0
    gatsby-plugin-htaccess: ^1.4.0 => 1.4.0
    gatsby-plugin-image: 1.4.0 => 1.4.0
    gatsby-plugin-manifest: ^3.4.0 => 3.4.0
    gatsby-plugin-react-helmet: ^4.4.0 => 4.4.0
    gatsby-plugin-robots-txt: ^1.5.6 => 1.5.6
    gatsby-plugin-sharp: ^3.4.0 => 3.4.0
    gatsby-plugin-sitemap: 4.0.0 => 4.0.0
    gatsby-plugin-styled-components: ^4.4.0 => 4.4.0
    gatsby-source-filesystem: ^3.4.0 => 3.4.0
    gatsby-source-wordpress: ^5.4.0 => 5.4.0
    gatsby-transformer-sharp: ^3.4.0 => 3.4.0
  npmGlobalPackages:
    gatsby-cli: 3.4.0

@pedrolamas
Copy link
Contributor

My understanding is that the gatsby-plugin-sitemap version 4.0.0 is generating the files under a /sitemap folder (that's where I see the files now)

Check the html headers in your generated files, search for "sitemap" and you will see the new path.

Having said that, I still think there must be some bug, as the index file has "/sitemap-0.xml" instead of the expected "/sitemap/sitemap-0.xml"

I've tried setting "output" to "" in the config, but apparently, gatsby doesn't allow generating the sitemaps on the root now...

@holliepearson
Copy link

holliepearson commented Apr 29, 2021

I can confirm I can find the files in /public/sitemap. Is there a particular reason this change was made? Just seems odd to deviate from the default sitemap location.

For anyone using a plugin such as gatsby-plugin-robots-txt you will need to update the path to your sitemap. Same applies for manually generated files or submitted urls. Perhaps a note on the plugin page would help?

It looks like you can still generate the sitemap files in the root by doing output: "/" which fixes the bug where the sitemap-index.xml links to the incorrect location but I agree it should be pointing to the correct location by default/follow what output is set as.

@pedrolamas
Copy link
Contributor

Using output: "/" is not ideal as the header gets generated with "//sitemap-index.xml"... not sure what is the reasoning to now allow output: "", but that would probably fix the whole thing!

@mikeyfe6
Copy link
Author

mikeyfe6 commented Apr 29, 2021

I'm also having issue with the sitemap plugin with Error: Page array from `query` wasn't found at `data.allSitePage.nodes`.

I had the same issue, it was saying something about adding a 'resolvePages' function

@mikeyfe6
Copy link
Author

My understanding is that the gatsby-plugin-sitemap version 4.0.0 is generating the files under a /sitemap folder (that's where I see the files now)

Check the html headers in your generated files, search for "sitemap" and you will see the new path.

Having said that, I still think there must be some bug, as the index file has "/sitemap-0.xml" instead of the expected "/sitemap/sitemap-0.xml"

I've tried setting "output" to "" in the config, but apparently, gatsby doesn't allow generating the sitemaps on the root now...

Thanksss, that brings me a step further. I can find mine at 'http://localhost:9000/sitemap/sitemap-0.xml', now i'm tryna figure out why it's not at the root what @pedrolamas said...

@mikeyfe6
Copy link
Author

mikeyfe6 commented Apr 29, 2021

I've putted this together with the v4 documentation, and its working like before..

{
      resolve: 'gatsby-plugin-sitemap',
      options: {
        query: `
        {
          allSitePage {
            nodes {
              path
              context {
                updatedAt
              }
            }
          }
          allContentfulBlogPost {
            nodes {
              ... on ContentfulBlogPost {
                slug
              }
            }
          }
        }
      `,
        resolveSiteUrl: () => siteUrl,
        resolvePages: ({
          allSitePage: { nodes: allPages },
          allContentfulBlogPost: { nodes: allCfNodes },
        }) => {
          const cfNodeMap = allCfNodes.reduce((acc, node) => {
            const { slug } = node;
            acc[slug] = node;

            return acc;
          }, {});

          return allPages.map((page) => ({ ...page, ...cfNodeMap[page.path] }));
        },
        serialize: ({ path, context }) => ({
          url: path,
          changefreq: 'daily',
          priority: 0.7,
          lastmod: context.updatedAt,
        }),
      },
    },

Hope this helps you out as well guys, PS: i'm still looking for the simple /sitemap.xml slug option.. but this gets me a lot further.

@pedrolamas
Copy link
Contributor

pedrolamas commented Apr 29, 2021

Mine is here, if anyone is interested (but has the issues reported above): https://github.com/pedrolamas/pedrolamas.com/blob/bf3c9107f6b1f33a431972dcbac55be1d361ce71/gatsby-config.js#L169-L194

@pedrolamas
Copy link
Contributor

I've submitted a small PR that will allow setting output: "" in the options so that the sitemap files are generated on the root on the public folder just as it did before! Let's hope someone notices and merges it soon! 🙂

@Floriferous
Copy link

I can confirm that reverting to 3.3.0 fixes the issue.

Careful about the breaking change from options.exclude to options.excludes that isn't mentioned anywhere...

@moonmeister
Copy link
Contributor

Thanks all for the notes. I think the /sitemap sub folder was partially accidental as the underlying dependency changed somethings. This dependency is probably what's causing the bad /sitemap-0.xml path. I'll look into resolving these issues and checking out any proposed PRs.

@moonmeister
Copy link
Contributor

I'm closing this cause it's gotten quite off topic and the original problem was solved. I have opened an issue for incorrect folder path (#31167). If you have an issue different from the original that isn't resolved please open an issue. Thanks all.

@flikteoh
Copy link

flikteoh commented May 1, 2021

I'm still getting errors even with the minimal config.

plugins: [`gatsby-plugin-sitemap`]

is the resolvePages: ({ allSitePage: { nodes: allPages }}) required even for only local mdx files?

@moonmeister
Copy link
Contributor

Hi @flikteoh !

Sorry to hear you're running into an issue. To help us best begin debugging the underlying cause, it is incredibly helpful if you open a new issue. Please include a minimal reproduction and a copy of any relevant code/config or a link to the repository.

Thanks for using Gatsby! 💜

@LekoArts LekoArts removed the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label May 3, 2021
@dcxSt
Copy link

dcxSt commented May 15, 2021

I'm also having issue with the sitemap plugin with Error: Page array from `query` wasn't found at `data.allSitePage.nodes`.

Hi, I had the same issue @flikteoh , since I didn't want the sitemap to start with, I just deleted it from gatsby-config.js and then removed the plugin from my project npm remove gatsby-plugin-sitemap, then ran gatsby clean and gatsby build and it worked!

@moonmeister : don't know if this is very helpful there, but I didn't find a new issue... here is my config file:

module.exports = {
  siteMetadata: {
    title: "gatsby-personal",
  },
  plugins: [
    "gatsby-plugin-image",
    {
      resolve: "gatsby-plugin-manifest",
      options: {
        icon: "src/images/icon.png",
      },
    },
    "gatsby-transformer-remark",
    "gatsby-plugin-sharp",
    "gatsby-transformer-sharp",

    {
      resolve: "gatsby-plugin-mdx",
      options: {
        gatsbyRemarkPlugins: [
          {
            resolve: "gatsby-remark-images",
            options: {
              maxWidth: 1200,
            },
          },
        ],
      },
    },

    {
      resolve: "gatsby-source-filesystem",
      options: {
        name: "images",
        path: "./src/images/",
      },
      __key: "images",
    },
    {
      resolve: "gatsby-source-filesystem",
      options: {
        name: "src",
        path: "./src/",
      },
    },
  ],
};

@gatsbyjs gatsbyjs locked and limited conversation to collaborators May 15, 2021
@moonmeister
Copy link
Contributor

@dcxSt If you have an issue, please open a new one.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants