question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[plugin-sitemap] filter undefined

See original GitHub issue

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® 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:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
epguicommented, Jan 27, 2020

@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.

2reactions
moonmeistercommented, Jan 18, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Gatsby sitemap generator isn't filterting the pages
I'm trying to generate sitemaps via gatsby-plugin-sitemap and it works with all the default options and generate the sitemaps however if I ...
Read more >
gatsby-plugin-sitemap
filterPages (function) Takes the current page and a string (or other object) from the exclude array and expects a boolean to be returned....
Read more >
Generate an SEO-Friendly Sitemap for your Gatsby Site
Whenever we build our site, this plugin will generate a sitemap.xml file, alongside all the other files that Gatsby builds. Critically, this ...
Read more >
@dexus1985/eleventy-plugin-sitemap - npm
Start using @dexus1985/eleventy-plugin-sitemap in your project by ... By default it is undefined and the plugin will fallback to `date`.
Read more >
Gatsby advanced sitemap, serializer proper usage
{ resolve: `gatsby-plugin-advanced-sitemap`, options: { query: ` { allBlogPostDe: allContentfulBlogPost(filter: {node_locale: {eq: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found