[plugin-sitemap] filter undefined
See original GitHub issueDescription
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® Core™ 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
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
@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 ofedges.node
.For both of these, allowing a function to be passed in would be ideal.
filter could do the same thing, take a string and the internal filter is used against
edges
ornodes
. 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.