Invariant Violation: Encountered an error trying to infer a GraphQL type for: `tags___NODE`

Invariant Violation: Encountered an error trying to infer a GraphQL type for: `tags___NODE`


0

I am new to Gatsby. I’m creating a blog site using Gatsby and Contentful as CMS. On creating a field ‘timeToRead’ I’m getting an error as

ERROR #11321 API.NODE.EXECUTION

"gatsby-source-contentful" threw an error while running the sourceNodes lifecycle:

_node$fields.includes is not a function

However whenever I clear cache and rebuild the appliction it works fine. But without that I always encounter this error.

My gatsby-node.js file :

const { documentToPlainTextString } = require("@contentful/rich-text-plain-text-renderer")
const words = require('lodash/words');

exports.onCreateNode = async ({ node, actions }) => {
  const { createNodeField } = actions;
  if (node.internal.type !== "ContentfulBlogPost") {
    return ;
  }
  // Match the "bodyContent" below to match the name of your rich text field
  const data = JSON.parse(node.blogContent.raw);
  const allText = documentToPlainTextString(data);
  const countPerMinute = 200;
  const totalWords = words(allText).length;
  var time = Math.round(totalWords / countPerMinute);
  if (time === 0) time=1;
  createNodeField({ node, name: 'timeToRead', value: time })
}

I’m using the following libraries as listed in package.json

  "dependencies": {
    "@contentful/rich-text-plain-text-renderer": "^16.0.7",
    "@emotion/react": "^11.10.6",
    "@emotion/styled": "^11.10.6",
    "@mui/icons-material": "^5.11.11",
    "@mui/material": "^5.11.13",
    "@portabletext/react": "^2.0.2",
    "aos": "^2.3.4",
    "axios": "^1.5.0",
    "dotenv": "^16.3.1",
    "gatsby": "^5.8.0",
    "gatsby-plugin-image": "^3.8.0",
    "gatsby-plugin-sharp": "^5.8.1",
    "gatsby-source-contentful": "^8.12.3",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-helmet": "^6.1.0",
    "react-image-gallery": "^1.3.0",
    "typewriter-effect": "^2.19.0"
  }

New contributor

Krishna Kolte is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


Load 7 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *