question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Gatsby Build Fail: Invariant Violation with GraphQL Type

See original GitHub issue

Description

Gatsby build suddenly fails (seemed to begin failing over night on webhook deployments).

Environment

Gatsby version: 1.9.134 Node.js version: 6.9.4 Operating System: OSX 10.12.6

File contents (if changed):

gatsby-config.js:

module.exports = {
  plugins: [
    `gatsby-plugin-react-helmet`,
    {
      resolve: `gatsby-source-contentful`,
      options: {
        spaceId: `redacted`,
        accessToken: `redacted`
      }
    },
    `gatsby-transformer-remark`,
    `gatsby-plugin-glamor`,
    {
      resolve: `gatsby-plugin-typography`,
      options: {
        pathToConfigModule: `src/utils/typography`
      }
    }
  ]
};

package.json:

{
  "name": "personal-blog",
  "description": "Alex M Lewis Blog",
  "version": "1.0.0",
  "author": "Alex Lewis <alexmichael.lewis@gmail.com>",
  "dependencies": {
    "gatsby": "^1.9.127",
    "gatsby-link": "^1.6.30",
    "gatsby-plugin-glamor": "^1.6.10",
    "gatsby-plugin-react-helmet": "^1.0.8",
    "gatsby-plugin-typography": "^1.7.10",
    "gatsby-source-contentful": "^1.3.29",
    "gatsby-transformer-remark": "^1.7.24",
    "glamorous": "^4.11.0",
    "lodash": "^4.17.4",
    "typography-theme-irving": "^0.15.10"
  },
  "license": "MIT",
  "main": "index.js",
  "scripts": {
    "build": "gatsby build",
    "develop": "gatsby develop",
    "format": "prettier --trailing-comma es5 --no-semi --single-quote --write \"src/**/*.js\""
  },
  "devDependencies": {
    "prettier": "^1.9.0"
  }
}

gatsby-node.js:

const Promise = require(`bluebird`);
const path = require(`path`);
const slash = require(`slash`);

exports.createPages = ({ graphql, boundActionCreators }) => {
  const { createPage } = boundActionCreators;
  return new Promise((resolve, reject) => {
    graphql(`
      {
        allContentfulPost {
          edges {
            node {
              slug
            }
          }
        }
      }
    `).then(result => {
      if (result.errors) {
        reject(result.errors);
      }

      // Create Product pages
      const productTemplate = path.resolve(`./src/templates/post-page.js`);
      // We want to create a detailed page for each
      // product node. We'll just use the Contentful id for the slug.
      result.data.allContentfulPost.edges.map(({ edge }) => {
        createPage({
          // Each page is required to have a `path` as well
          // as a template component. The `context` is
          // optional but is often necessary so the template
          // can query data specific to each page.
          path: `/${edge.node.slug}/`,
          component: slash(productTemplate),
          context: {
            slug: edge.node.slug
          }
        });
      });
    });
    resolve();
  });
};

gatsby-browser.js: No change gatsby-ssr.js: No change

Actual result

10:20:37 AM: Fetch Contentful data: 216.303ms
10:20:37 AM: success source and transform nodes — 0.372 s
10:20:37 AM: error Encountered an error trying to infer a GraphQL type for: "createdEntries___NODE". There is no corresponding node with the id field matching: "null"
10:20:37 AM: 

  Error: Invariant Violation: Encountered an error trying to infer a GraphQL typ  e for: "createdEntries___NODE". There is no corresponding node with the id fie  ld matching: "null"
  
  - invariant.js:42 invariant
    [repo]/[invariant]/invariant.js:42:15
  
  - infer-graphql-type.js:265 validateLinkedNode
    [repo]/[gatsby]/dist/schema/infer-graphql-type.js:265:5
  
  - infer-graphql-type.js:340 inferFromFieldName
    [repo]/[gatsby]/dist/schema/infer-graphql-type.js:340:3
  
  - infer-graphql-type.js:580 
    [repo]/[gatsby]/dist/schema/infer-graphql-type.js:580:23
  
  - lodash.js:4944 
    [repo]/[lodash]/lodash.js:4944:15
  
  - lodash.js:3001 baseForOwn
    [repo]/[lodash]/lodash.js:3001:24
  
  - lodash.js:4913 
    [repo]/[lodash]/lodash.js:4913:18
  
  - lodash.js:9359 Function.forEach
    [repo]/[lodash]/lodash.js:9359:14
  
  - infer-graphql-type.js:554 inferObjectStructureFromNodes
    [repo]/[gatsby]/dist/schema/infer-graphql-type.js:554:5
  
  - build-node-types.js:239 createNodeFields
    [repo]/[gatsby]/dist/schema/build-node-types.js:239:34
  
  - build-node-types.js:79 fields
    [repo]/[gatsby]/dist/schema/build-node-types.js:79:26
  

Expected behavior

It should be building.

Steps to reproduce

1. Create a new gatsby project with gatsby new project-folder

2. Replace the above files with their respective contents

3. gatsby develop

I have tried removing all GraphQL related queries and am still running into the the issue. Any help/ideas is greatly appreciated! …

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
sarahatworkcommented, Dec 15, 2017

@mpaarating I think I’ve seen an error like that before from having corrupt data on Contentful, like if you have an association that’s been deleted. Might this be the cause?

screenshot 2017-12-15 15 04 41
0reactions
alana314commented, Dec 9, 2019

FWIW, we started getting this error when we had an asset with the same ID as an entry ID.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Invariant Violation: gatsby-source-graphql requires option ...
{ resolve: "gatsby-source-graphql", options: { // This type will contain remote schema Query type typeName: "Query", // This is field under ...
Read more >
Encountered an error trying to infer a GraphQL type for ...
Contentful data that causes Invariant Violation: Encountered an error trying to infer a GraphQL type for contentModel. Here's a fix.
Read more >
Troubleshooting Common Errors - Gatsby
If the error is describing an Unknown field 'X' on type 'Query' , the content type you are trying to source is likely...
Read more >
Common Gatsby JS Error Encounter During Development
Gatsby develop error in CLI version 2.7.49 ... Invariant Violation: Encountered an error trying to infer a GraphQL type for: `apps___NODE`.
Read more >
Suddenly Strapi content is not showing in GraphQL query
Everything was working well, I had created a content type of Job and ... I'm assuming I shouldn't run 'gatsby build' yet, am...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found