I reinstalled all npm modules without yarn.lock and got this error. In the demo-repo I saved yarn.lock that breaks build. Also I added yarn.lock.nice with which build works fine.
gatsby build returns the following error:
ERROR #85910 GRAPHQL
Multiple "root" queries found: "yQuery" and "BlogPostBySlug".
Only the first ("BlogPostBySlug") will be registered.
Instead of:
1 | query BlogPostBySlug {
2 | allMarkdownRemark {
3 | #...
4 | }
5 | }
6 |
7 | query yQuery {
8 | site {
9 | #...
10 | }
11 | }
Do:
1 | query yQueryAndBlogPostBySlug {
2 | allMarkdownRemark {
3 | #...
4 | }
5 | site {
6 | #...
7 | }
8 | }
This can happen when you use two page/static queries in one file. Please combine those into one query.
If you're defining multiple components (each with a static query) in one file, you'll need to move each component to its own file.
File: src/templates/blog-post.tsx
I've prepared demo repo
After clonning do the following steps:
yarn install
gatsby build
build should complete
build failed
System:
OS: Linux 4.15 Ubuntu 16.04.6 LTS (Xenial Xerus)
CPU: (8) x64 AMD FX(tm)-8350 Eight-Core Processor
Shell: 4.3.48 - /bin/bash
Binaries:
Node: 10.14.1 - /usr/local/bin/node
Yarn: 1.17.3 - /usr/bin/yarn
npm: 6.4.1 - /usr/local/bin/npm
Languages:
Python: 2.7.12 - /usr/bin/python
Browsers:
Chrome: 76.0.3809.87
npmPackages:
gatsby: ^2.3.16 => 2.18.17
gatsby-image: ^2.0.37 => 2.2.37
gatsby-plugin-feed: ^2.1.0 => 2.3.25
gatsby-plugin-google-analytics: ^2.0.18 => 2.1.31
gatsby-plugin-lodash: ^3.0.5 => 3.1.18
gatsby-plugin-mailchimp: ^5.1.0 => 5.1.2
gatsby-plugin-manifest: ^2.0.28 => 2.2.34
gatsby-plugin-netlify-cache: ^1.2.0 => 1.2.0
gatsby-plugin-netlify-cms: ^4.1.33 => 4.1.33
gatsby-plugin-offline: ^2.0.25 => 2.2.10
gatsby-plugin-prefetch-google-fonts: ^1.4.2 => 1.4.3
gatsby-plugin-react-helmet: ^3.0.12 => 3.1.18
gatsby-plugin-sharp: ^2.0.32 => 2.3.10
gatsby-plugin-styled-components: ^3.0.7 => 3.1.16
gatsby-plugin-typescript: ^2.0.12 => 2.1.23
gatsby-remark-copy-linked-files: ^2.0.11 => 2.1.33
gatsby-remark-images: ^2.0.6 => 2.0.6
gatsby-remark-katex: ^3.0.4 => 3.1.20
gatsby-remark-mermaid: ^1.0.0 => 1.2.0
gatsby-remark-prismjs: ^3.2.8 => 3.3.28
gatsby-remark-relative-images: ^0.2.3 => 0.2.3
gatsby-remark-responsive-iframe: ^2.1.1 => 2.2.30
gatsby-remark-smartypants: ^2.0.9 => 2.1.19
gatsby-source-filesystem: ^2.0.29 => 2.1.43
gatsby-source-instagram: ^0.5.0 => 0.5.1
gatsby-transformer-remark: ^2.3.8 => 2.6.45
gatsby-transformer-sharp: ^2.1.17 => 2.3.9
npmGlobalPackages:
gatsby-cli: 2.7.53
So the issue is you have multiple queries inside the PageQuery export. Not sure if you wanted to use that yQuery at the end as it is not referenced anywhere else in that template. try deleting it and rerunning the build
@lannonbr, thank you for your fast feedback.
After deleting it works. But why did it work with multiple queries and old yarn.lock (in the demo repo yarn.lock.nice)?
I have no idea why it worked that way, but when you export a page query in a template or page, it should only have 1 root query.
I got it. Thank you.
We reworked query extraction recently. The new extractor discovered this error when the old one (erroneously) skipped it.
thanks, @vladar
I'm getting the error in the default blog starter template:
Multiple "root" queries found: "BlogPostBySlug" and "BlogPostBySlug"
There is only one root query on my template file templates/blog-post.js. When it's removed, the homepage loads, but none of the posts work. Is this an issue with the version of gatsbly CLI?
Most helpful comment
I'm getting the error in the default blog starter template:
Multiple "root" queries found: "BlogPostBySlug" and "BlogPostBySlug"
There is only one root query on my template file templates/blog-post.js. When it's removed, the homepage loads, but none of the posts work. Is this an issue with the version of gatsbly CLI?