gatsbyjs / gatsby

The best React-based framework with performance, scalability and security built in.
https://www.gatsbyjs.com
MIT License
55.3k stars 10.31k forks source link

After npm update to 2.18.5, ERROR #85910 GRAPHQL Multiple "root" queries found in file: "IndexPageTemplate" and "IndexPageTemplate". #19863

Closed dan-mba closed 4 years ago

dan-mba commented 5 years ago

Description

I was seeing the problem described in #19748 , but after npm update picked up 2.18.5 the build failed with a different error (which was repeated for several files):

ERROR #85910 GRAPHQL

Multiple "root" queries found in file: "IndexPageTemplate" and "IndexPageTemplate". Only the first ("IndexPageTemplate") will be registered.

Instead of: 1 | query IndexPageTemplate { 2 | bar { 3 | #... 4 | } 5 | } 6 | 7 | query IndexPageTemplate { 8 | foo { 9 | #... 10 | } 11 | }

Do: 1 | query indexPageTemplateAndIndexPageTemplate { 2 | bar { 3 | #... 4 | } 5 | foo { 6 | #... 7 | } 8 | }

File: src\templates\index-page.js

Steps to reproduce

  1. clone starter repo
  2. npm install
  3. npm update
  4. npm run build

Expected result

build should complete

Actual result

build failed

Environment

System: OS: Windows 8.1 6.3.9600 CPU: (4) x64 Intel(R) Core(TM) i5-4460S CPU @ 2.90GHz Binaries: Node: 12.13.1 - C:\Program Files\nodejs\node.EXE npm: 6.12.1 - C:\Program Files\nodejs\npm.CMD Languages: Python: 3.8.0 npmPackages: gatsby: ^2.18.5 => 2.18.5 gatsby-image: ^2.2.34 => 2.2.34 gatsby-plugin-netlify: ^2.1.27 => 2.1.27 gatsby-plugin-netlify-cms: ^4.1.30 => 4.1.30 gatsby-plugin-purgecss: ^4.0.0 => 4.0.1 gatsby-plugin-react-helmet: ^3.1.16 => 3.1.16 gatsby-plugin-sass: ^2.1.24 => 2.1.24 gatsby-plugin-sharp: ^2.3.4 => 2.3.4 gatsby-remark-copy-linked-files: ^2.1.31 => 2.1.31 gatsby-remark-images: ^3.1.34 => 3.1.34 gatsby-remark-relative-images: ^0.2.1 => 0.2.3 gatsby-source-filesystem: ^2.1.39 => 2.1.39 gatsby-transformer-remark: ^2.6.38 => 2.6.38 gatsby-transformer-sharp: ^2.3.6 => 2.3.6

vladar commented 5 years ago

Probably related: https://github.com/gatsbyjs/gatsby/pull/19665

freiksenet commented 5 years ago

Sorry, but I can't reproduce this with 2.18.5 :(

Could you try cleaning .cache, public and node_modules and trying again?

dan-mba commented 5 years ago

OK, things just got weird.

I did everything you said on my Windows 8 development system. I deleted node_modules and re-ran npm install. I ran gatsby clean. The build still fails.

I pushed my updated package.json to my github repo so I could see if my repo failed for you as well. This caused Netlify to rebuild my site. The Netlify build is run on Linux & it completed successfully.

So now I need help determining what external tools the "extract queries from components" step uses. Does this step use any of the node-gyp binaries? I had to set this up for this project & have no idea if my setup is correct.

andrejarboe commented 5 years ago

I am having the same issues

vladar commented 5 years ago

Can you please provide a minimum reproduction? That would help a lot!

dan-mba commented 5 years ago

@vladar I have no experience with gatsby, so I have no clue how to isolate the problem.

This is my first gatsby project, and the only thing I have changed from the starter is package.json by running npm update.

Is there a verbose option for the build process to get more information?

vladar commented 5 years ago

@andrejarboe Are you on Windows as well?

vladar commented 5 years ago

@dan-mba I suspect it may have something to do with your CMD on windows. When you run npm run build command - does it show c:\some\path or C:\some\path (note the capital drive letter)?

And maybe try switching to the opposite version before running npm run build just to confirm.

Lars-m commented 5 years ago

I had the same problem as outlined by several users above The hint above, related to CMD made me try to use git-bash instead of my Windows terminal, and that solved the problem. If I, from a windows terminal, clone, my project, npm install, npm upgrade and Gatsby build, then I get the "Multiple 'root' queries ...' error If I do exactly the same, via git bash, everything is fine :-)

dan-mba commented 5 years ago

@vladar You have isolated the problem

netlify-blog@1.0.0 build c:\Dev\github\netlify-blog npm run clean && gatsby build

This is how I normally run & it fails

netlify-blog@1.0.0 build C:\Dev\github\netlify-blog npm run clean && gatsby build

I did a cd to change to the capital drive letter & the build completed.

Both were done in the standard windows terminal.

So is this a problem with how the gatsby CLI handles the drive letter?

vladar commented 5 years ago

Yeah. File deduplication doesn't work because the library we use for path normalization doesn't handle drive letters (and maybe it shouldn't). As a result, we assume that you have two template files with identical content hence the error.

dan-mba commented 5 years ago

@vladar Thanks for your help. I set my terminal to start in the capitalized directory so I shouldn't see the problem anymore.

Mognoid3r commented 5 years ago

I'm having this exact issue and I have no idea how to solve it.
ERROR #85910 GRAPHQL

Multiple "root" queries found in file: "cSomeFile" and "cSomeFile". Only the first ("cSomeFile") will be registered.

These queries are the same files. Can someone please help me solve this issue? I have my graphQl in the index.js:

import React from "react"; import { Link, graphql } from "gatsby";

import Layout from "../components/layout"; import SEO from "../components/seo"; // import Hero from '../components/Globals/Hero'; import Info from '../components/home/Info'; import BackgroundSection from "../components/Globals/BackgroundSection";

const IndexPage = ({data}) => (

{/* */}

);

export const query = graphql{ img:file(relativePath:{eq:"cbg2.jpg"}) { childImageSharp { fluid(maxWidth: 400, maxHeight: 250) { ...GatsbyImageSharpFluid } } } menu:allContentfulCoffeeItem{ edges{ node{ id title description{ description } price category image{ fixed(width:50,height:50){ ...GatsbyContentfulFixed_tracedSVG } } } } } }

export default IndexPage

dan-mba commented 5 years ago

@Mognoid3r you just need to cd to your base directory with a capital drive letter before building. cd C:\path\to\gatsby npm run build

Mognoid3r commented 5 years ago

Forgive me but how do you do that? i'm new to all this. I use the terminal inside of VSC but when I git clone I do that out of git bash.

dan-mba commented 5 years ago

@Mognoid3r What command are you running when you get the error? What does your prompt look like on the place you issue that command?

I was seeing this problem when running npm run build from the windows terminal.

Mognoid3r commented 5 years ago

Inside VSC I open up my terminal inside of the root of my project and I use the command gatsby develop.

dan-mba commented 5 years ago

@Mognoid3r Cut & paste what your VSC terminal looks like when you first open it.

Mognoid3r commented 5 years ago

Holis@DESKTOP-VA208DU MINGW64 ~/Desktop/practice/Test-Coffee-Repo (master) $

dan-mba commented 5 years ago

@Mognoid3r Your VSC terminal is using git bash, which I am not very familiar with, but try these commands:

cd /C/Users/Holis/Desktop/practice/Test-Coffee-Repo gatsby develop

bristoljon commented 5 years ago

I just hit this where I had 2 hook exports in the same file. Not sure why it is an issue but in the end I separated the exports into their own files combining them in the index.js file of the directory:

// /hooks/index.js
export { default as useSiteMeta } from './useSiteMeta';
export { default as useContactDetails } from './useContactDetails';
laradevitt commented 5 years ago

I'm also seeing the Multiple "root" queries found in file error but in a new project.

This occurs with a template component shadowed from a theme. Are we supposed to rename queries when we shadow components (or just components containing page queries)? This is the sort of thing that would probably be obvious to everyone but me! I haven't seen it documented anywhere.

See Issue #2 in this demo repo.

I am also on Windows (see below), but the cd/base directory trick didn't change anything for me.

Cheers -

  System:
    OS: Windows 10 10.0.17763
    CPU: (8) x64 Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz
  Binaries:
    Node: 12.13.0 - ~\AppData\Local\Temp\yarn--1575659192406-0.508817745209361\node.CMD
    Yarn: 1.19.1 - ~\AppData\Local\Temp\yarn--1575659192406-0.508817745209361\yarn.CMD
    npm: 6.12.0 - C:\Program Files\nodejs\npm.CMD
  Languages:
    Python: 3.7.2 - /c/Users/r2dfoo/AppData/Local/Programs/Python/Python37/python
  Browsers:
    Edge: 44.17763.831.0
andrejarboe commented 4 years ago

@andrejarboe Are you on Windows as well?

Yes I am on windows

Do I need to switch to Linux or Mac?

andrejarboe commented 4 years ago

@vladar Thanks for your help. I set my terminal to start in the capitalized directory so I shouldn't see the problem anymore.

How do you make it start with the capital C automatically?

dan-mba commented 4 years ago

@andrejarboe for command prompt or powershell, just set the "start in" directory on the shortcut you use to have a capital drive letter. For Git Bash, there doesn't seem to be a good way as it always forces the drive letter to lower case outside of doing a "cd /C"

murnana commented 4 years ago

me too. repo: https://github.com/murnana/gatsby-bug-repo/tree/feature/gatsbyjs%2319863

paulio commented 4 years ago

I had this "hair puller" too, gave up and used CMD CLI rather than bash :(

typesafedev commented 4 years ago

Thanks for the help. I had this issue using powershell PS D:\Source\Dev\gatsby-starter-blog\ After wasting lots of time, gave up and used cmd rather than powershell.

Nurou commented 4 years ago

Experiencing the "Multiple "root" queries found in file" problem on macOS. Downgrading gatsby to version 2.17.* did not help - the error changed to "Encountered duplicate defintitions for one or more documents: each document must have a unique name"

vladar commented 4 years ago

@Nurou Yours sounds like a different problem because this one is windows-specific (and the bug here is that Gatsby finds a duplicate query in the same file).

In your situation, this message may indicate a real error in your code. So please post a full output of your error message.

vladar commented 4 years ago

The fix is published in gatsby-cli@2.8.27

RapidOwl commented 4 years ago

Just encountered this on Windows 10 while running Gatsby CLI 2.8.29. It was working fine last night. Booted my laptop today and all of a sudden Gatsby is telling me I've got multiple queries in my index.js. It builds fine in Git Bash or cmd.

Repo link: https://github.com/RapidOwl/samstrong-dot-dev

Update: This works fine in Git Bash stand alone, but when running Git Bash through Windows Terminal this fails.

geoom commented 4 years ago

@dan-mba it maybe would be related to a filenames conflict I had, I just got it solved, I hope it helps.

https://stackoverflow.com/a/60400516/1911787

joshdrumz commented 4 years ago

Has anyone found the solution to this issue? I'm running the latest version of gatsby-cli and still seem to get this error every time. All of my filenames are unique. I am running on Windows 10.

freedamoore commented 4 years ago

I had this issue while using the terminal in VS Code. Seems like it's case sensitive, so make sure the drive letter and all the folders match the actual cases.

So for me, the issue occurred because I had initially navigated to my destination folder by using a lower case "b" for my blog folder when I had created it with a capital "B". I fixed it by changing blog to Blog as per below:

From: C:\Documents\blog\gatsby-blog

To: C:\Documents\Blog\gatsby-blog

Hope this helps.

kdev29 commented 4 years ago

I had this issue while using the terminal in VS Code. Seems like it's case sensitive, so make sure the drive letter and all the folders match the actual cases.

So for me, the issue occurred because I had initially navigated to my destination folder by using a lower case "b" for my blog folder when I had created it with a capital "B". I fixed it by changing blog to Blog as per below:

From: C:\Documents\blog\gatsby-blog

To: C:\Documents\Blog\gatsby-blog

Hope this helps.

I was facing the same issue on my Windows 10 machine, and indeed is a case sensitivity thing, in my case I changed the letter "d" in C:\Users\leoc\documents\ to C:\Users\leoc\Documents\ and it built successfully in the powershell terminal on VSCode.

SachiniAbeygunawardhana commented 3 years ago

'gatsby clean' solved the issue I had the same issue when I was running an application on localhost (on Windows). I cleaned the cache using gatsby clean and re-started the application. It solved the issue.

jefflung commented 3 years ago

I had this issue while using the terminal in VS Code. Seems like it's case sensitive, so make sure the drive letter and all the folders match the actual cases.

So for me, the issue occurred because I had initially navigated to my destination folder by using a lower case "b" for my blog folder when I had created it with a capital "B". I fixed it by changing blog to Blog as per below:

From: C:\Documents\blog\gatsby-blog

To: C:\Documents\Blog\gatsby-blog

Hope this helps.

I m new for gatsby and I m using Windows 10, changing path words beginning letter with capital letter works for me, e.g. c://Users/me_/Documents/React/my-blog, both git-bash, windows terminal and vscode terminal