Skip to content

[plugin-sitemap] filter undefined #20692

@moonmeister

Description

@moonmeister

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedIssue with a clear description that the community can help with.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions