gatsbyjs / gatsby

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

Error: RelayParser: Encountered duplicate defintitions for one or more documents #11688

Closed ChildishhAlbino closed 5 years ago

ChildishhAlbino commented 5 years ago

Description

Building a blog / portfolio with GatsbyJS and I'm struggling with this issue. I had the website working for the most part but all of a sudden it's stopped working. Really not sure why. The error doesn't make much sense to me. Hoping someone cold help me work out why.

Steps to reproduce

https://github.com/ChildishhAlbino/childishhalbino.github.io/tree/problem-fixing

Above is a git repo with the project as I last left it.

  1. run NPM install for node packages
  2. Run gatsby develop.
  3. Visit localhost/8000

An error screen should appear with the above error.

Expected result

There will be warnings. There are some imports that aren't being used but aside from that everything should be fine.

Actual result

Environment

Run npx gatsby info --clipboard in your project directory and paste the output here.

System: OS: Windows 10 CPU: (4) x64 Intel(R) Core(TM) i5-6600K CPU @ 3.50GHz Binaries: npm: 6.4.1 - D:\Software Development\Languages, Frameworks, etc\nodeJs\npm.CMD Languages: Python: 3.7.0 - C:\Users\conno\AppData\Local\Programs\Python\Python37-32\python.EXE Browsers: Edge: 42.17134.1.0 npmPackages: gatsby: ^2.0.118 => 2.0.118 gatsby-image: ^2.0.19 => 2.0.29 gatsby-plugin-buildtime-timezone: ^1.0.3 => 1.0.3 gatsby-plugin-manifest: ^2.0.7 => 2.0.17 gatsby-plugin-offline: ^2.0.23 => 2.0.23 gatsby-plugin-react-helmet: ^3.0.1 => 3.0.6 gatsby-plugin-sass: ^2.0.2 => 2.0.10 gatsby-plugin-sharp: ^2.0.11 => 2.0.20 gatsby-source-filesystem: ^2.0.6 => 2.0.20 gatsby-transformer-remark: ^2.2.4 => 2.2.4 gatsby-transformer-sharp: ^2.1.7 => 2.1.13

error The system cannot find the path specified.

Error: The system cannot find the path specified.

error UNHANDLED REJECTION

Error: The system cannot find the path specified.

pieh commented 5 years ago

This is defenitely a bug in gatsby.

For now you can workaround this by changing line in https://github.com/ChildishhAlbino/childishhalbino.github.io/blob/problem-fixing/gatsby-node.js#L34 to:

component: path.resolve(`./src/components/Blog/BlogPostTemplate/blogPostTemplate.js`),

(I adjusted file/directory names casing to match one that exists in repository). It will get you pass that graphql error, but there will be some additional fixes needed elsewhere too because I hit:

error Building static HTML failed for path "/GatsbyJS and Web development/"

See our docs page on debugging HTML builds for help https://gatsby.app/debug-html

  11 |                  <div className="blurb">
  12 |                          <Image fluid={data.image.childImageSharp.fluid} />
> 13 |                          <Markdown source={data.blurb.childMarkdownRemark.rawMarkdownBody} />
     |                                                                           ^
  14 |                  </div>
  15 |          )}
  16 |  />

  WebpackError: TypeError: Cannot read property 'rawMarkdownBody' of null

But this is not really related to issue itself.

I will start working on fix to handle casing differences and to not throw this confusing error message.

ChildishhAlbino commented 5 years ago

Thanks for working that out for me! I actually didn't think it was a bug in Gatsby but whaddya know? ]

Quickly worked out those errors and the sites working again!

Thanks heaps :D

Have a nice day, good luck fixing the bug!

imshuffling commented 5 years ago

i think I'm having a similar issue, any update on a fix for this?

pieh commented 5 years ago

@imshuffling hopefully I'll open PR today. Just to confirm if your issue have similar root problem - are you on Mac? Because it seems that on Linux and Windows when you use wrong casing for component argument in createPage we will throw error saying that file can't be found.

imshuffling commented 5 years ago

@pieh Yeah I'm on a mac, i've logged a issue here - it may be related https://github.com/gatsbyjs/gatsby/issues/11732

pieh commented 5 years ago

Oh, this seems different. Error from this is: Error: RelayParser: Encountered duplicate defintitions for one or more documents

AlexanderProd commented 5 years ago

I'm encountering the same bug as well when I create a new gatsby project using this starter and run gatsby develop.

My error message:

GraphQL Error There was an error while compiling your site's GraphQL queries.
  Error: RelayParser: Encountered duplicate defintitions for one or more documents: each document must have a unique name. Duplicated documents:
- usersAlexanderhoerlSitesBiobalanceSrcTemplatesProductPageIndexJs721922104

I'm also on mac.

System:
    OS: macOS 10.14.3
    CPU: (8) x64 Intel(R) Core(TM) i7-4750HQ CPU @ 2.00GHz
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 11.7.0 - /usr/local/bin/node
    Yarn: 1.13.0 - /usr/local/bin/yarn
    npm: 6.5.0 - /usr/local/bin/npm
  Languages:
    Python: 2.7.10 - /usr/bin/python
  Browsers:
    Chrome: 72.0.3626.109
    Safari: 12.0.3
  npmPackages:
    gatsby: ^2.0.111 => 2.0.111 
    gatsby-image: ^2.0.20 => 2.0.25 
    gatsby-plugin-google-analytics: ^2.0.13 => 2.0.13 
    gatsby-plugin-layout: ^1.0.11 => 1.0.11 
    gatsby-plugin-manifest: ^2.0.9 => 2.0.12 
    gatsby-plugin-offline: ^2.0.16 => 2.0.20 
    gatsby-plugin-react-helmet: ^3.0.6 => 3.0.6 
    gatsby-plugin-sharp: ^2.0.14 => 2.0.16 
    gatsby-source-filesystem: ^2.0.8 => 2.0.12 
    gatsby-source-shopify2: ^2.0.7 => 2.0.7 
    gatsby-transformer-sharp: ^2.1.8 => 2.1.9 
pieh commented 5 years ago

@AlexanderProd From quick look it seems like same issue. This is because file path casing in https://github.com/AlexanderProd/gatsby-shopify-starter/blob/cff5d01029e514cf9ac8ac70987d01cd03a16f82/gatsby-node.js#L19 doesn't match casing exactly:

in gatsby-node: component: path.resolve(`./src/templates/ProductPage/index.js`),
in filesystem:                             src/templates/productPage/index.js
                                                         ^ one `p` is uppercase other is lower case

so as a workaround, adjusting path in gatsby-node should fix this.

AlexanderProd commented 5 years ago

@AlexanderProd From quick look it seems like same issue. This is because file path casing in https://github.com/AlexanderProd/gatsby-shopify-starter/blob/cff5d01029e514cf9ac8ac70987d01cd03a16f82/gatsby-node.js#L19 doesn't match casing exactly:

in gatsby-node: component: path.resolve(`./src/templates/ProductPage/index.js`),
in filesystem:                             src/templates/productPage/index.js
                                                         ^ one `p` is uppercase other is lower case

so as a workaround, adjusting path in gatsby-node should fix this.

I've noticed when I change it to a small p building and developing works on Ubuntu machines but not on macOS, what makes it pretty difficult to develop on a mac and build on a linux server.

ZolderonGitHub commented 5 years ago

i have same problem

mrcongliu commented 5 years ago

I met the same error. The problem is because I was using Hyper terminal in windows. Solution is using the default terminal in windows.

philkrause commented 5 years ago

I met the same error. The problem is because I was using Hyper terminal in windows. Solution is using the default terminal in windows.

This solved it for me. Thanks. I did not have this issue on mac.

john20xdoe commented 5 years ago

Additional info if anyone else stumble on this issue on Windows:

The gatsby npm run script is case-sensitive not only with the src file names, but including the entire path name:

I store all my projects in a folder in D: named Dev, (D:\Dev) The "duplicate definitions" error is picking on the entire path (im running in WSL Vscode): filesystem: /d/Dev/longreponame/gatsby-project/component-name-something is apparently different from what it is generating: page: /d/dev/longreponame/gatsby-project/component-name-something

I had to rename the Dev folder to lowercase just to fix it.

patrick-wc commented 5 years ago

Gatsby should really add a warning to any Windows users about having capital letters in their dir names. This must stump quite a few users.

drillprop commented 5 years ago

I met the same error. The problem is because I was using Hyper terminal in windows. Solution is using the default terminal in windows.

works for me too, thank you!

cleophasmogeni commented 5 years ago

This error can be quite vague for starters but it is actually a warning due to the case sensitive nature of gatsby run scripts. For example: avoid this Myblog in you file path. You can use myblog or even myBlog

djD-REK commented 5 years ago

Gatsby should really add a warning to any Windows users about having capital letters in their dir names. This must stump quite a few users.

Thanks @patrick-wc ! It did stump me!

mickm77 commented 5 years ago

On Windows 10 using git bash, i was getting these errors/warnings because I had typed cd /c/dev/git/projectname code .

I quit code, and did cd /C/Dev/Git/projectname code .

And it all just worked...

lowtolerance commented 5 years ago

This started happening to me, seemingly out of nowhere. Exiting out of the command line and reentering seemed to do the trick

8ctopotamus commented 5 years ago

This is still happening using Git Bash in VSCode terminal on Windows.

Git Bash by itself works fine.

patrik-u commented 4 years ago

On Windows 10 using git bash, i was getting these errors/warnings because I had typed cd /c/dev/git/projectname code .

I quit code, and did cd /C/Dev/Git/projectname code .

And it all just worked...

Fixed it for me as well. Used Windows PowerShell and worked when I typed cd FolderName with correct casing.

benflinn commented 4 years ago

wow i just randomly started having the same error. played around with different content folders for like half an hour before I realized that definitely wasn't it. after renaming my project folder it's working 100% now instantly.

8ctopotamus commented 4 years ago

I have found that explicitly typing out cd ~/path/to/project avoids this issue (Using Gitbash in VSCode).

Coffeegerm commented 4 years ago

This is still occurring when I run gatsby develop within a PowerShell prompt on Windows, but not when using the Command Prompt

assainov commented 4 years ago

For me the error was introduced when I duplicated a src/template/template.js. I moved the file to src/fonts/ folder to eliminate this variant, but gatsby found it even there. Moving the file out of src folder resolved the issue. I think it has to do with a GraphQL queries being similar in different templates.

KishokanthJeganathan commented 4 years ago

I had this same issue with when I was having the below code in 2 pages

export const query = graphql`
    query contentFulAddBlogPost($slug: String, $locale: String) {
        contentfulAddBlogPost(path: { eq: $slug }, node_locale: { eq: $locale }) {
            path
            node_locale
        }
    }
`;

to avoid this I changed contentFulAddBlogPost to allContentFulAddBlogPost in one of the components as below

export const query = graphql`
    query allContentFulAddBlogPost($slug: String, $locale: String) {
        contentfulAddBlogPost(path: { eq: $slug }, node_locale: { eq: $locale }) {
            path
            node_locale
        }
    }
`;

worked like a charm. hope it helps you guys in the future :)