Gatsby: [plugin-sitemap] filter undefined

Created on 18 Jan 2020  路  6Comments  路  Source: gatsbyjs/gatsby

Description

I recently got a the following error:

 ERROR #11321  PLUGIN

"gatsby-plugin-sitemap" threw an error while running the onPostBuild lifecycle:

Cannot read property 'filter' of undefined

At first I was confused, I wasn't calling filter any where, I realized the plugin was probably using Array.prototype.filter() internally to filter urls in the exclude field. That's when I realized the problem. My query was written:

allSitePage{
    nodes {
      path
      context {
        title
        modified
      }
    }
  }

While the plugin examples were written:

allSitePage{
    edges {
      node{
        path
        context {
          title
          modified
       }
     }
    }
  }

That meant the filter function didn't exist because the data structure was different then expected by the plugin.

Steps to reproduce

skip the graphql edges node and use nodes in your allSitePages query

Expected result

I'd expect both data structures to work, should be easy enough to do some detection logic to figure out what structure was used and filter appropriately.

Environment

System:
OS: Linux 5.3 Ubuntu 19.10 (Eoan Ermine)
CPU: (8) x64 Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
Shell: 5.0.3 - /bin/bash
Binaries:
Node: 12.14.1 - /tmp/yarn--1579323808977-0.10414995248476577/node
Yarn: 1.21.1 - /tmp/yarn--1579323808977-0.10414995248476577/yarn
npm: 6.13.4 - ~/.nvm/versions/node/v12.14.1/bin/npm
Languages:
Python: 2.7.17 - /usr/bin/python
Browsers:
Chrome: 79.0.3945.88
Firefox: 72.0.1
npmPackages:
gatsby: ^2.18.3 => 2.18.22
gatsby-image: ^2.2.33 => 2.2.39
gatsby-plugin-manifest: ^2.2.29 => 2.2.37
gatsby-plugin-netlify: ^2.1.30 => 2.1.31
gatsby-plugin-offline: ^3.0.23 => 3.0.32
gatsby-plugin-preact: ^3.1.24 => 3.1.25
gatsby-plugin-purgecss: ^4.0.1 => 4.0.1
gatsby-plugin-react-helmet: ^3.1.15 => 3.1.21
gatsby-plugin-sass: ^2.1.26 => 2.1.27
gatsby-plugin-sharp: ^2.3.3 => 2.3.13
gatsby-plugin-sitemap: ^2.2.26 => 2.2.26
gatsby-source-filesystem: ^2.1.38 => 2.1.46
gatsby-source-graphql: ^2.1.24 => 2.1.31
gatsby-transformer-json: ^2.2.25 => 2.2.25
gatsby-transformer-sharp: ^2.3.5 => 2.3.13

help wanted

Most helpful comment

For both of these, allowing a function to be passed in would be ideal.

//this is effectivly the default
resolveSiteUrl: (data) => {
return data.siteMetadata.siteUrl
}

//or in my case
resolveSiteUrl: () => siteUrl

filter could do the same thing, take a string and the internal filter is used against edges or nodes. If it takes a function it simply passes the results of the query, and maybe the glob tool into the function, and lets me do the rest.

PS: I might be able to do this work, just not for a couple weeks probably.

All 6 comments

I also just ran into:

"gatsby-plugin-sitemap" threw an error while running the onPostBuild lifecycle:

Cannot read property 'siteMetadata' of undefined



  TypeError: Cannot read property 'siteMetadata' of undefined

Again makes an assumption about the query. In my case I'm dynamically determining the siteUrl based on NETLIFY env vars and could have passed it in directly, i realized after looking there was no way to do so.

For both of these, allowing a function to be passed in would be ideal.

//this is effectivly the default
resolveSiteUrl: (data) => {
return data.siteMetadata.siteUrl
}

//or in my case
resolveSiteUrl: () => siteUrl

filter could do the same thing, take a string and the internal filter is used against edges or nodes. If it takes a function it simply passes the results of the query, and maybe the glob tool into the function, and lets me do the rest.

PS: I might be able to do this work, just not for a couple weeks probably.

Hi @moonmeister !

Sorry to hear you're running into an issue. To help us best begin debugging the underlying cause, it is incredibly helpful if you're able to create a minimal reproduction. This is a simplified example of the issue that makes it clear and obvious what the issue is and how we can begin to debug it.

If you're up for it, we'd very much appreciate if you could provide a minimal reproduction and we'll be able to take another look.

Thanks for using Gatsby! 馃挏

I'll try to find time, about to travel for a couple weeks and probably won't have time.

@TylerBarnes I think the above description is pretty much on the nose. I'm getting the same issue _when and only when_ I use nodes instead of edges.node.

Hiya!

This issue has gone quiet. Spooky quiet. 馃懟

We get a lot of issues, so we currently close issues after 30 days of inactivity. It鈥檚 been at least 20 days since the last update here.
If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open!
As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks for being a part of the Gatsby community! 馃挭馃挏

Was this page helpful?
0 / 5 - 0 ratings