Repository: gatsbyjs/gatsby

Issue #31903: gatsby-plugin-sitemap not generating sitemap with default options when running yarn build
Created: 2021-06-14T15:12:40Z
Description
When running yarn build gatsby-plugin-sitemap is generating following error:
 ERROR #11321  PLUGIN

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

Page array from `query` wasn't found at `data.allSitePage.nodes`.
      Fix the custom query or provide a custom `resolvePages` function.
      https://www.gatsbyjs.com/plugins/gatsby-plugin-sitemap/#api-reference


  46 |             queryRecords = _yield$graphql.data;
  47 |             _context.next = 8;
> 48 |             return Promise.resolve(resolvePages(queryRecords)).catch(function (err) {
     |                                    ^
  49 |               return reporter.panic(_internals.REPORTER_PREFIX + " Error resolving Pages", err);
  50 |             });
  51 |

File: node_modules/gatsby-plugin-sitemap/gatsby-node.js:48:36



  Error: Page array from `query` wasn't found at `data.allSitePage.nodes`.
        Fix the custom query or provide a custom `resolvePages` function.
        https://www.gatsbyjs.com/plugins/gatsby-plugin-sitemap/#api-reference

However I'm using default options and when looking on the graphql query, it is actually generating the paths on the allSitePage query.
Steps to reproduce
Initialize a gatsby project:

gatsby new test
set node version to 12 nvm use 12
add gatsby-plugin-sitemap yarn add gatsby-plugin-sitemap
yarn build

Expected result
gatsby-plugin-sitemap creates a sitemap
Actual result
Not finishing the build
Environment

  System:
    OS: Linux 5.8 Ubuntu 20.04.2 LTS (Focal Fossa)
    CPU: (8) x64 Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 14.17.0 - ~/.nvm/versions/node/v14.17.0/bin/node
    Yarn: 1.22.5 - /usr/bin/yarn
    npm: 6.14.13 - ~/.nvm/versions/node/v14.17.0/bin/npm
  Languages:
    Python: 3.9.1 - /home/javierpiedra/miniconda3/bin/python
  Browsers:
    Chrome: 91.0.4472.101
    Firefox: 89.0
  npmPackages:
    gatsby: ^3.6.2 => 3.6.2 
    gatsby-plugin-gatsby-cloud: ^2.6.1 => 2.6.1 
    gatsby-plugin-image: ^1.6.0 => 1.6.0 
    gatsby-plugin-manifest: ^3.6.0 => 3.6.0 
    gatsby-plugin-offline: ^4.6.0 => 4.6.0 
    gatsby-plugin-react-helmet: ^4.6.0 => 4.6.0 
    gatsby-plugin-sharp: ^3.6.0 => 3.6.0 
    gatsby-plugin-sitemap: ^4.3.1 => 4.3.1 
    gatsby-source-filesystem: ^3.6.0 => 3.6.0 
    gatsby-transformer-sharp: ^3.6.0 => 3.6.0 
  npmGlobalPackages:
    gatsby-cli: 3.7.0

Duplicate issue #31944: Build fails on fresh Gatsby starter with gatsby-plugin-sitemap
Created: 2021-06-16T13:09:27Z
Description
Running gatsby build or npm run build fails right after creating a fresh site using gatsby-cli new and the sitemap plugin. There is no specific documentation on additional required steps in the tutorial or build output.
Steps to reproduce

Run npx gatsby-cli new
Select options


no cms
no styling system
add an automatic sitemap


Observe a success message "Your new Gatsby site has been successfully created"
Run npm run build

Expected result
The build either succeeds or I am notified about any additional steps required after creating a fresh site at the end of gatsby-cli new.
Actual result
An error message
> npm run build                                                                                                    15:07:21

> test@1.0.0 build /Users/work/code/test
> gatsby build

success open and validate gatsby-configs - 0.050s
success load plugins - 0.185s
success onPreInit - 0.024s
success initialize cache - 0.007s
success copy gatsby files - 0.119s
success Compiling Gatsby Functions - 0.492s
success onPreBootstrap - 0.512s
success createSchemaCustomization - 0.002s
success Checking for changed pages - 0.001s
success source and transform nodes - 0.030s
success building schema - 0.242s
success createPages - 0.001s
success createPagesStatefully - 0.034s
info Total nodes: 24, SitePage nodes: 3 (use --verbose for breakdown)
success Checking for changed pages - 0.001s
success update schema - 0.038s
success onPreExtractQueries - 0.001s
success extract queries from components - 0.097s
success write out redirect data - 0.002s
success onPostBootstrap - 0.001s
info bootstrap finished - 4.598s
success run page queries - 0.009s - 3/3 328.96/s
success write out requires - 0.006s
success Building production JavaScript and CSS bundles - 5.073s
success Rewriting compilation hashes - 0.002s
success Building HTML renderer - 0.791s
success Building static HTML for pages - 0.114s - 3/3 26.29/s

 ERROR #11321  PLUGIN

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

Page array from `query` wasn't found at `data.allSitePage.nodes`.
      Fix the custom query or provide a custom `resolvePages` function.
      https://www.gatsbyjs.com/plugins/gatsby-plugin-sitemap/#api-reference


  46 |             queryRecords = _yield$graphql.data;
  47 |             _context.next = 8;
> 48 |             return Promise.resolve(resolvePages(queryRecords)).catch(function (err) {
     |                                    ^
  49 |               return reporter.panic(_internals.REPORTER_PREFIX + " Error resolving Pages", err);
  50 |             });
  51 |

File: node_modules/gatsby-plugin-sitemap/gatsby-node.js:48:36



  Error: Page array from `query` wasn't found at `data.allSitePage.nodes`.
        Fix the custom query or provide a custom `resolvePages` function.
        https://www.gatsbyjs.com/plugins/gatsby-plugin-sitemap/#api-reference

  - internals.js:101 resolvePages
    [test]/[gatsby-plugin-sitemap]/internals.js:101:11

  - gatsby-node.js:48 _callee$
    [test]/[gatsby-plugin-sitemap]/gatsby-node.js:48:36


not finished onPostBuild - 0.081s

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! test@1.0.0 build: `gatsby build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the test@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/work/.npm/_logs/2021-06-16T13_07_36_292Z-debug.log

Environment
> npx gatsby info --clipboard                                                                                      15:08:20

  System:
    OS: macOS 11.4
    CPU: (8) x64 Intel(R) Core(TM) i5-8259U CPU @ 2.30GHz
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 12.18.4 - ~/.nvm/versions/node/v12.18.4/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 6.14.6 - ~/.nvm/versions/node/v12.18.4/bin/npm
  Languages:
    Python: 2.7.16 - /usr/bin/python
  Browsers:
    Safari: 14.1.1
  npmPackages:
    gatsby: ^3.6.2 => 3.7.2
    gatsby-plugin-sitemap: ^4.3.1 => 4.3.1

Closing comment (2021-06-16T13:15:45Z): Hi!
This is a duplicate of #31903