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

Netlify GraphQL error: duplicate definitions #15997

Closed angelod1as closed 5 years ago

angelod1as commented 5 years ago

EDIT: read my second reply to this issue first for better clarification of the problem. Thanks.

Description

gatsby build runs smoothly. When I push to Netlify, the Error: RelayParser: Encountered duplicate defintitions for one or more documents: each document must have a unique name. appears. I changed all my filenames to lowercase to avoid case problems and the error persists.

Steps to reproduce

Run this project on branch netlify-error. First, yarn, then gatsby develop. Here, no errors. gatsby build, nice, no errors again. Tested in local server, everything great. git push to Github and Netlify... error.

Expected result

The site should build without errors.

Actual result

The error appeared.

Environment

  System:
    OS: macOS 10.14.5
    CPU: (4) x64 Intel(R) Core(TM) i5-4278U CPU @ 2.60GHz
    Shell: 5.3 - /bin/zsh
  Binaries:
    Node: 12.1.0 - /usr/local/bin/node
    Yarn: 1.17.3 - ~/.yarn/bin/yarn
    npm: 6.9.0 - /usr/local/bin/npm
  Languages:
    Python: 2.7.15 - /usr/local/bin/python
  Browsers:
    Chrome: 75.0.3770.142
    Firefox: 67.0.4
    Safari: 12.1.1
  npmPackages:
    gatsby: ^2.13.33 => 2.13.33
    gatsby-background-image: ^0.8.0 => 0.8.0
    gatsby-cli: ^2.7.17 => 2.7.17
    gatsby-image: ^2.2.6 => 2.2.6
    gatsby-plugin-catch-links: ^2.1.2 => 2.1.2
    gatsby-plugin-google-fonts: ^1.0.1 => 1.0.1
    gatsby-plugin-manifest: ^2.2.4 => 2.2.4
    gatsby-plugin-netlify-cms: ^4.1.6 => 4.1.6
    gatsby-plugin-offline: ^2.2.4 => 2.2.4
    gatsby-plugin-react-helmet: ^3.1.2 => 3.1.2
    gatsby-plugin-react-svg: ^2.1.1 => 2.1.1
    gatsby-plugin-sharp: ^2.2.9 => 2.2.9
    gatsby-plugin-styled-components: ^3.1.2 => 3.1.2
    gatsby-remark-images: ^3.1.7 => 3.1.7
    gatsby-remark-lazy-load: ^1.0.1 => 1.0.1
    gatsby-remark-picture: ^1.0.1 => 1.0.1
    gatsby-remark-relative-images: ^0.2.2 => 0.2.2
    gatsby-remark-unwrap-images: ^1.0.1 => 1.0.1
    gatsby-source-filesystem: ^2.1.6 => 2.1.6
    gatsby-transformer-remark: ^2.6.9 => 2.6.9
    gatsby-transformer-sharp: ^2.2.4 => 2.2.4
  npmGlobalPackages:
    gatsby-cli: 2.7.17

Netlify full message:

1:24:18 AM: Build ready to start
1:24:20 AM: build-image version: 9e0f207a27642d0115b1ca97cd5e8cebbe492f63
1:24:20 AM: build-image tag: v3.3.2
1:24:20 AM: buildbot version: ef8d0929ed0baabafd8bbb7d0b021e1fc24180c0
1:24:20 AM: Fetching cached dependencies
1:24:20 AM: Failed to fetch cache, continuing with build
1:24:20 AM: Starting to prepare the repo for build
1:24:21 AM: No cached dependencies found. Cloning fresh repo
1:24:21 AM: git clone https://github.com/angelod1as/mae-urso
1:24:22 AM: Preparing Git Reference refs/heads/master
1:24:23 AM: Starting build script
1:24:23 AM: Installing dependencies
1:24:24 AM: Downloading and installing node v10.16.0...
1:24:24 AM: Downloading https://nodejs.org/dist/v10.16.0/node-v10.16.0-linux-x64.tar.xz...
1:24:25 AM: 
#########
1:24:25 AM:                 12.9%
1:24:25 AM: 
##############################################################
1:24:25 AM: ########## 100.0%
1:24:25 AM: Computing checksum with sha256sum
1:24:25 AM: Checksums matched!
1:24:28 AM: Now using node v10.16.0 (npm v6.9.0)
1:24:28 AM: Attempting ruby version 2.6.2, read from environment
1:24:29 AM: Using ruby version 2.6.2
1:24:30 AM: Using PHP version 5.6
1:24:30 AM: Started restoring cached node modules
1:24:30 AM: Finished restoring cached node modules
1:24:30 AM: Started restoring cached yarn cache
1:24:30 AM: Finished restoring cached yarn cache
1:24:30 AM: Installing yarn at version 1.13.0
1:24:30 AM: Installing Yarn!
1:24:30 AM: > Downloading tarball...
1:24:30 AM: [1/2]: https://yarnpkg.com/downloads/1.13.
1:24:30 AM: 0/yarn-v1.13.0.tar.gz --> /tmp/yarn.tar.gz.5mmAFEJ4l4
1:24:30 AM:   % Total    % Receive
1:24:30 AM: d % Xferd  Average Speed   Time    Time     Time  Curren
1:24:30 AM: t
1:24:30 AM:     Dload  Upload   Total   Spent    Left  Spee
1:24:30 AM: d
1:24:30 AM: 
  0     0    0     0    0
1:24:30 AM:      0      0      0 --:--:-- --:--:-- --:--:--     0
1:24:30 AM: 
100    93  100    93    0     0    3
1:24:30 AM: 94      0 --:--:-- --:--:-- --:--:--   395
1:24:30 AM: 
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
1:24:30 AM: 
100   609    0   609    0     0   1059      0 --:--:-- --:--:-
1:24:30 AM: - --:--:--  6766
1:24:31 AM: 
100 1142k  100 1142k    0     0  1165k      0 --:--:-- --:--:
1:24:31 AM: -- --:--:-- 1165k
1:24:31 AM: [2/2]: https://yarnpkg.co
1:24:31 AM: m/downloads/1.13.0/yarn-v1.13.0.tar.gz.asc --> /tmp/ya
1:24:31 AM: rn.tar.gz.5mmAFEJ4l4.asc
1:24:31 AM: 
100    97  100    97    0     0   2441
1:24:31 AM:       0 --:--:-- --:--:-- --:--:--  2441
1:24:31 AM: 
100   613    0   613    0     0   4204      0 --:--:-- --:--
1:24:31 AM: :-- --:--:--  4204
1:24:31 AM: 
100   832  100   832    0     0
1:24:31 AM: 4553      0 --:--:-- --:--:-- --:--:--  4553
1:24:31 AM: > Verifying integrity...
1:24:31 AM: gpg: Signature made Tue 18 Dec 2018 04:04:55 PM UTC using RSA key ID B6FF4DE3
1:24:31 AM: gpg: Good signature from "Yarn Packaging <yarn@dan.cx>"
1:24:31 AM: gpg: Note: This key has expired!
1:24:31 AM: Primary key fingerprint: 72EC F46A 56B4 AD39 C907  BBB7 1646 B01B 86E5 0310
1:24:31 AM:      Subkey fingerprint: E219 30C4 D0A4 AA46 1858  1F7A E074 D16E B6FF 4DE3
1:24:31 AM: > GPG signature looks good
1:24:31 AM: > Extracting to ~/.yarn...
1:24:31 AM: > Adding to $PATH...
1:24:31 AM: > We've added the following to your /opt/buildhome/.profile
1:24:31 AM: > If this isn't the profile of your current shell then please add the following to your correct profile:
1:24:31 AM: export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
1:24:31 AM: 
1:24:32 AM: > Successfully installed Yarn 1.13.0! Please open another terminal where the `yarn` command will now be available.
1:24:32 AM: Installing NPM modules using Yarn version 1.13.0
1:24:33 AM: yarn install v1.13.0
1:24:33 AM: [1/4] Resolving packages...
1:24:34 AM: [2/4] Fetching packages...
1:24:59 AM: info fsevents@1.2.9: The platform "linux" is incompatible with this module.
1:24:59 AM: info "fsevents@1.2.9" is an optional dependency and failed compatibility check. Excluding it from installation.
1:24:59 AM: [3/4] Linking dependencies...
1:24:59 AM: warning " > babel-loader@8.0.6" has unmet peer dependency "webpack@>=2".
1:24:59 AM: warning " > eslint-plugin-import@2.18.2" has unmet peer dependency "eslint@2.x - 6.x".
1:24:59 AM: warning " > eslint-plugin-jsx-a11y@6.2.3" has unmet peer dependency "eslint@^3 || ^4 || ^5 || ^6".
1:24:59 AM: warning " > eslint-plugin-react@7.14.3" has unmet peer dependency "eslint@^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0".
1:24:59 AM: warning " > gatsby-plugin-styled-components@3.1.2" has unmet peer dependency "babel-plugin-styled-components@>1.5.0".
1:24:59 AM: warning "netlify-cms-app > netlify-cms-widget-markdown > slate-edit-list@0.11.3" has incorrect peer dependency "slate@^0.32.0".
1:24:59 AM: warning "netlify-cms-app > netlify-cms-widget-markdown > slate-edit-table@0.15.2" has incorrect peer dependency "slate@^0.33.3".
1:24:59 AM: warning "netlify-cms-app > netlify-cms-widget-markdown > slate-edit-table@0.15.2" has unmet peer dependency "slate-schema-violations@^0.1.7".
1:24:59 AM: warning "netlify-cms-app > netlify-cms-core > redux-notifications > react-redux@4.4.10" has incorrect peer dependency "redux@^2.0.0 || ^3.0.0".
1:24:59 AM: warning " > eslint-config-airbnb@17.1.1" has unmet peer dependency "eslint@^4.19.1 || ^5.3.0".
1:24:59 AM: warning "eslint-config-airbnb > eslint-config-airbnb-base@13.2.0" has unmet peer dependency "eslint@^4.19.1 || ^5.3.0".
1:24:59 AM: warning " > eslint-config-prettier@6.0.0" has unmet peer dependency "eslint@>=3.14.1".
1:24:59 AM: warning " > eslint-plugin-prettier@3.1.0" has unmet peer dependency "eslint@>= 5.0.0".
1:25:10 AM: [4/4] Building fresh packages...
1:25:15 AM: Done in 42.43s.
1:25:15 AM: NPM modules installed using Yarn
1:25:16 AM: Started restoring cached go cache
1:25:16 AM: Finished restoring cached go cache
1:25:16 AM: unset GOOS;
1:25:16 AM: unset GOARCH;
1:25:16 AM: export GOROOT='/opt/buildhome/.gimme/versions/go1.12.linux.amd64';
1:25:16 AM: export PATH="/opt/buildhome/.gimme/versions/go1.12.linux.amd64/bin:${PATH}";
1:25:16 AM: go version >&2;
1:25:16 AM: export GIMME_ENV='/opt/buildhome/.gimme/env/go1.12.linux.amd64.env';
1:25:16 AM: go version go1.12 linux/amd64
1:25:16 AM: Installing missing commands
1:25:16 AM: Verify run directory
1:25:16 AM: Executing user command: gatsby build
1:25:19 AM: success open and validate gatsby-configs — 0.101
1:25:20 AM: success load plugins — 1.431
1:25:20 AM: success onPreInit — 0.027
1:25:20 AM: success delete html and css files from previous builds — 0.021
1:25:20 AM: success initialize cache — 0.023
1:25:20 AM: success copy gatsby files — 0.033
1:25:20 AM: success onPreBootstrap — 0.020
1:25:21 AM: success source and transform nodes — 0.424
1:25:21 AM: success building schema — 0.532
1:25:21 AM: success createPages — 0.090
1:25:21 AM: success createPagesStatefully — 0.037
1:25:21 AM: success onPreExtractQueries — 0.016
1:25:22 AM: success update schema — 0.066
1:25:22 AM: error #85901 GRAPHQL
1:25:22 AM: There was an error in your GraphQL query:
1:25:22 AM: Error: RelayParser: Encountered duplicate defintitions for one or more documents: each document must have a unique name. Duplicated documents:
1:25:22 AM: - optBuildRepoSrcComponentsSeoJs2417117884
1:25:22 AM: - optBuildRepoSrcTemplatesHomeOpeningJs1748048373
1:25:22 AM: See our docs page for more info on this error: https://gatsby.dev/issue-how-to
1:25:22 AM: Skipping functions preparation step: no functions directory set
1:25:22 AM: Caching artifacts
1:25:22 AM: Started saving node modules
1:25:22 AM: Finished saving node modules
1:25:22 AM: Started saving yarn cache
1:25:22 AM: Finished saving yarn cache
1:25:22 AM: Started saving pip cache
1:25:22 AM: Finished saving pip cache
1:25:22 AM: Started saving emacs cask dependencies
1:25:22 AM: Finished saving emacs cask dependencies
1:25:22 AM: Started saving maven dependencies
1:25:22 AM: Finished saving maven dependencies
1:25:22 AM: Started saving boot dependencies
1:25:22 AM: Finished saving boot dependencies
1:25:22 AM: Started saving go dependencies
1:25:22 AM: Finished saving go dependencies
1:25:25 AM: Error running command: Build script returned non-zero exit code: 1
1:25:25 AM: Failing build: Failed to build site
1:25:25 AM: failed during stage 'building site': Build script returned non-zero exit code: 1
1:25:25 AM: Finished processing build request in 1m4.965322518s

Gatsby config:

const path = require('path')

module.exports = {
  siteMetadata: {
    title: `Mãe Urso Culinária`,
    description: `Homepage for Mãe Urso cooking and events`,
    author: `@angelod1as`,
  },
  plugins: [
    `gatsby-plugin-react-helmet`,
    `gatsby-plugin-catch-links`,
    `gatsby-plugin-styled-components`,
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `assets`,
        path: path.join(__dirname, `static`, `assets`),
      },
    },
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `images`,
        path: path.join(__dirname, `src`, `images`),
      },
    },
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `src`,
        path: path.join(__dirname, `src`),
      },
    },
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `content`,
        path: path.join(__dirname, `content`),
      },
    },
    {
      resolve: 'gatsby-transformer-remark',
      options: {
        plugins: [
          `gatsby-remark-relative-images`,
          {
            resolve: `gatsby-remark-images`,
            options: {
              maxWidth: 1500,
            },
          },
          'gatsby-remark-unwrap-images',
          'gatsby-remark-picture',
          `gatsby-remark-lazy-load`,
          {
            resolve: `gatsby-plugin-google-fonts`,
            options: {
              fonts: [`Amaranth:400,400i,700,700i`, `Lora:400,400i,700,700i`],
              display: 'swap',
            },
          },
        ],
      },
    },
    {
      resolve: `gatsby-plugin-react-svg`,
      options: {
        rule: {
          include: path.join(__dirname, `src`, `svg`),
        },
      },
    },
    `gatsby-transformer-sharp`,
    `gatsby-plugin-sharp`,
    `gatsby-plugin-netlify-cms`,
    {
      resolve: `gatsby-plugin-manifest`,
      options: {
        name: `gatsby-starter-default`,
        short_name: `starter`,
        start_url: `/`,
        background_color: `#663399`,
        theme_color: `#663399`,
        display: `minimal-ui`,
        // icon: `src/images/gatsby-icon.png`, // This path is relative to the root of the site.
      },
    },
    // this (optional) plugin enables Progressive Web App + Offline functionality
    // To learn more, visit: https://gatsby.dev/offline
    // `gatsby-plugin-offline`,
  ],
}

Gatsby node

const path = require(`path`)
const { createFilePath } = require(`gatsby-source-filesystem`)
const { fmImagesToRelative } = require('gatsby-remark-relative-images')

exports.onCreateNode = async ({ node, getNode, actions }) => {
  const { createNodeField } = actions

  // cria paths relativos das imagens
  await fmImagesToRelative(node)

  // select only markdown
  if (node.internal.type === `MarkdownRemark`) {
    // Making type
    const makeType = () => {
      const split = node.fileAbsolutePath.split('content/')[1]
      let type = ''
      if (split.indexOf('/') > 0) {
        ;[type] = split.split('/')
      } else {
        type = 'pages'
      }
      return type
    }

    const makeSlug = () => {
      const split = node.fileAbsolutePath.split('content/')[1]
      let slug = ''
      if (split.indexOf('/') > 0) {
        ;[, slug] = split.split('/')
      } else {
        slug = split
      }
      return slug.replace('.mdx', '').replace('.md', '')
    }

    // create slugs
    await createNodeField({
      node,
      name: `slug`,
      value: makeSlug(),
    })

    // Making type
    await createNodeField({
      node,
      name: `type`,
      value: makeType(),
    })

    const basePath = `content`

    // create fullPaths
    const fullPath = createFilePath({ node, getNode, basePath })

    await createNodeField({
      node,
      name: `fullPath`,
      value: fullPath,
    })
  }
}

exports.createPages = async ({ actions, graphql }) => {
  const { createPage } = actions

  // ########
  // BLOG
  // ########

  const getBlog = () =>
    graphql(`
      query {
        allMarkdownRemark(
          filter: { fields: { type: { eq: "blog" } } }
          sort: { order: DESC, fields: frontmatter___date }
        ) {
          edges {
            node {
              fields {
                type
                fullPath
              }
            }
          }
        }
      }
    `)

  const blogQl = await getBlog()

  if (blogQl.errors) throw new Error(blogQl.errors)

  // creating main blog page
  createPage({
    path: '/blog',
    component: path.resolve('src/templates/blog/blog.js'),
    context: {},
  })

  // creating each blog post
  blogQl.data.allMarkdownRemark.edges.forEach(({ node }) => {
    createPage({
      path: node.fields.fullPath,
      component: path.resolve(`src/templates/blog/post.js`),
      context: {},
    })
  })

  // ########
  // cardapios
  // ########

  const getcardapio = () =>
    graphql(`
      query {
        allMarkdownRemark(
          filter: { fields: { type: { eq: "cardapios" } } }
          sort: { order: DESC, fields: frontmatter___date }
        ) {
          edges {
            node {
              fields {
                type
                slug
                fullPath
              }
            }
          }
        }
      }
    `)

  const cardapiosQl = await getcardapio()

  if (cardapiosQl.errors) throw new Error(cardapiosQl.errors)

  // creating main cardapio page
  createPage({
    path: '/cardapios',
    component: path.resolve('src/templates/cardapios/cardapios.js'),
    context: {},
  })

  // creating each cardapio
  cardapiosQl.data.allMarkdownRemark.edges.forEach(({ node }) => {
    createPage({
      path: node.fields.fullPath,
      component: path.resolve(`src/templates/cardapios/cardapio.js`),
      context: {},
    })
  })

  // ########
  // HOME COMPONENTS
  // ########

  const getHome = () =>
    graphql(`
      query {
        allMarkdownRemark(
          filter: { fields: { type: { eq: "home" } } }
          sort: { order: DESC, fields: frontmatter___date }
        ) {
          edges {
            node {
              fields {
                type
                slug
                fullPath
              }
            }
          }
        }
      }
    `)

  const homeQl = await getHome()

  if (homeQl.errors) throw new Error(homeQl.errors)

  // creating main home page
  createPage({
    path: '/',
    component: path.resolve('src/templates/home/main.js'),
    context: {},
  })

  // #########
  // PAGES
  // #########

  const getPages = () => {
    return graphql(`
      {
        allMarkdownRemark(
          filter: { fields: { type: { eq: "pages" } } }
          sort: { order: DESC, fields: frontmatter___date }
        ) {
          edges {
            node {
              fields {
                type
                slug
                fullPath
              }
            }
          }
        }
      }
    `)
  }

  const pagesQl = await getPages()

  if (pagesQl.errors) throw new Error(pagesQl.errors)

  // creating main home page
  // createPage({
  //   path: '/',
  //   component: path.resolve('src/templates/home.js'),
  //   context: {},
  // })

  // creating each sub pages
  pagesQl.data.allMarkdownRemark.edges.forEach(({ node }) => {
    createPage({
      path: node.fields.fullPath,
      component: path.resolve(`src/templates/pages/pages.js`),
      context: {},
    })
  })
}

15530 is a similar error without apparent solution.

angelod1as commented 5 years ago

I got the problem. gatsby-remark-images puts a link inside every image, and I had a link over it.

Solution: add linkImagesToOriginal: false to gatsby-reamark-images

          {
            resolve: `gatsby-remark-images`,
            options: {
              maxWidth: 1500,
              linkImagesToOriginal: false,
            },
          },
angelod1as commented 5 years ago

I was wrong in my own question.

I found out that, even after renaming my files (eg: Opening to opening), git continued to commit TWO documents: Opening and opening, resulting in the following error:

There was an error in your GraphQL query:
RelayParser: Encountered duplicate defintitions for one or more documents: each document must have a unique name.

The problem has nothing to do with GraphQL and/or directly Gatsby. Actually, this is the question I'm asking: is this a Gatsby bug?

The solution: Deleted opening.js, created a new file open.js and pasted the code there. Did the same to another file that was outputting the same error.

gatsbot[bot] commented 5 years ago

Hiya!

This issue has gone quiet. Spooky quiet. 👻

We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here.

If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open!

As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks for being a part of the Gatsby community! 💪💜

gatsbot[bot] commented 5 years ago

Hey again!

It’s been 30 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it.

Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m HUMAN_EMOTION_SORRY. Please feel free to reopen this issue or create a new one if you need anything else.

As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks again for being part of the Gatsby community!