Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gatsby-source-contentful] Error at fresh installment #3064

Closed
cpannwitz opened this issue Nov 29, 2017 · 28 comments
Closed

[gatsby-source-contentful] Error at fresh installment #3064

cpannwitz opened this issue Nov 29, 2017 · 28 comments
Labels
stale? Issue that may be closed soon due to the original author not responding any more. type: bug An issue or pull request relating to a bug in Gatsby

Comments

@cpannwitz
Copy link

Hey. I'm currently trying to setup a basic gatsby site with the contentful-source-plugin.
Last week everything went pretty great, until that moment I had to show off my results and - bam - the whole thing went down in 5 minutes. I had no success in recreating and debugging.

Specifically gatsby-source-contentful errors out with the following:
entryItemFields[foreignReference.name].push is not a function

Preconditions:
node -v: 8.9.1
gatsby-cli -v: 1.1.24
gatsby-cource-contentful version: tried everyone from 1.3.20 to 1.3.28

Steps to reproduce:

  1. npm i -g gatsby-cli
  2. gatsby new testdir && cd testdir
  3. yarn add gatsby-source-contentful -S
  4. Editing gatsby-config.js
plugins: [
    {
      resolve: `gatsby-source-contentful`,
      options: {
        spaceId: `MY_CORRECT_SPACEID`,
        accessToken: `MY_CORRECT_ACCESS_TOKEN`,
      },
    },
    `gatsby-plugin-react-helmet`
  ],
  1. (optionally) Editing gatsby-node.js and inserting/editing code from example gatsby-contentful-site

Thanks for any help!

@cpannwitz
Copy link
Author

cpannwitz commented Nov 29, 2017

Seems to be related with Contentful itself.
Creating a new workspace without any content doesn't throw.

My Contentful content type structure:
https://preview.ibb.co/mTg4kG/Bildschirmfoto_2017_11_29_um_11_39_05.png

None of these fields are empty, no other Locale is enabled than the default (German).

EDIT:

Managed to get it to work, by deleting the field References (many) on my second content type.
It referenced entries from the first content type, wasn't empty or (I assume) otherwise corrupted.

Are there any known issues with this specific content field type?

@KyleAMathews
Copy link
Contributor

This sounds like a genuine bug — would you like to put together a PR for this?

@cpannwitz
Copy link
Author

I can try to find out, whats the problem, but I'm not sure if I know enough about this specific plugin or gatsby's way of handling data. So, can't promise anything 🤷‍♂️

@KyleAMathews
Copy link
Contributor

Ok :-)

Start by adding console.logs around where the error is happening in the plugin — that's what I do to understand what type of data is triggering the error and how to handle it.

@e1moreno
Copy link

e1moreno commented Dec 5, 2017

I am encountering this issue as well. It seems to be tied to references. As cpannwitz described, the issue resolves itself when removing the references from the content altogether. It does not need to be removed from the content model. Note, in my case the reference was a "One Reference," and like cpannwitz, the reference was populated.

Something curious, in my case, the reference did not give me issues at first. It wasn't until I attempted to implement onCreateNode. The issue then persists until I clear the reference in Contentful. Doesn't make much sense as to why this would occur, perhaps I'm just overthinking it 😄

EDIT: This may very well be an issue with Contentful or my frequency in changing my Content models. Noticing data being published under old structures. I will try again tomorrow and give an update.

Attaching my log.
gatsby-reference-failure.log

@cpannwitz
Copy link
Author

I experienced the same, @Garbonauta .
At first, there was no error. Seems like contentful and/or the source-plugin needs some time to update the queried data.
Also I experienced - like you - that there was no way back, when the References field was introduced to the content model. It errors out afterwards, no matter what you change clientside or at contentful.

I tend to think, it has something to do with the "subscription" to data of the source-plugin to contentful. (as far as I know, you can simply query data from contentful, but also "subscribe" to it - api-wise)

@e1moreno
Copy link

e1moreno commented Dec 7, 2017

@cpannwitz I fully agree. I was able to circumvent the issue for about a day. I had to redo the Content models and content to get it to work. Luckily, I am at testing so this is no big deal. However, once I had the need to edit the content. The issue appeared again.

Like you I noticed the following:

  • References are dropped altogether. For my edited contents the references were null. Untouched elements remained pristine. Note, gatsby did launch and did not error out on compile time
  • The issue with compile time occurred when I deleted those invalid elements. It is like they are negotiating on the deleted element. I would have to recreate the deleted element for gatsby to compile.

At this point, I would like to know what do we do from here? What is the next step and I'll take it.

@mrtannerjones
Copy link

Same issue - references were the cause of the problem for me as well.

@e1moreno
Copy link

e1moreno commented Dec 8, 2017

I think I may be on the right track as to what is happening. It appears the plugin, gatsby-source-contentful, is, for the most part, pulling the right information from contentful. I still have some suspicions as to whether this statement is correct as I still had more issues described below.

I think what is happening, is that for example:
If you delete a piece of content in contentful. The data pulled from contentful does not match what is in Gatsby's redux store, cached in .cache/redux-state.json. Gatsby appears to use this cache file to compare expected information so it does not build the entire store every time you run gatsby develop. Thus, since the store data and pulled contentful data do not much, Gatsby crashes at compile time as it expects elements which are missing.
A quick fix for this is deleting the redux-state.json cache and rerunning gatsby. A new redux store is created and compilation appears to complete for the most part.

Now, I do not think this is the entire issue, I was still encountering problems where the recreated redux store did not include the missing reference types. Causing my code to crash at runtime. However, the issue appears to have fixed itself, not sure how, as I was doing some risky and ultimately useless manipulation of the redux-state.json file. I say useless, because it was in one instance where I deleted the store and it was correctly recreated.

For now, everything is working for me. I do expect the issue to reappear as I am still changing content models and the content itself in contentful. I will continue to take a look and see what I can find.

@fk fk added the API/Plugins label Feb 10, 2018
@tomjowitt
Copy link

tomjowitt commented Mar 18, 2018

I also have this issue but it occurs at build time. Like other issues in this thread, it occurs when using contentful references and createPages in gatsby-node.js.

Fetch Contentful data: 3785.866ms
error Plugin gatsby-source-contentful returned an error

  TypeError: entryItemFields[foreignReference.name].push is not a function
  
  - normalize.js:291 
    [site]/[gatsby-source-contentful]/normalize.js:291:52
  
  - Array.forEach
  
  - normalize.js:288 
    [site]/[gatsby-source-contentful]/normalize.js:288:27
  
  - Array.map
  
  - normalize.js:243 
    [site]/[gatsby-source-contentful]/normalize.js:243:30
  
  - Array.forEach
  
  - normalize.js:226 Object.exports.createContentTypeNodes
    [site]/[gatsby-source-contentful]/normalize.js:226:11
  
  - gatsby-node.js:179 
    [site]/[gatsby-source-contentful]/gatsby-node.js:179:25
  
  - Array.forEach
  
  - gatsby-node.js:178 _callee$
    [site]/[gatsby-source-contentful]/gatsby-node.js:178:30

@captainsask
Copy link

Just wondering if there had been any updates on this issue. I'm seeing the same thing as soon as I added references into my contentful data. It seems to be happening on build or develop. I tried using the previous method of deleting the redux-state.json in cache then rerunning but it doesn't seem to make a difference.

@zanedev
Copy link
Contributor

zanedev commented Sep 20, 2018

I'm now seeing this also with Contentful on Gatsby V2 and gatsby-source-contentful v2.0.1. Would be nice if these errors from data modeling were more specific as to where exactly the problem is. I'm way too far in my data model and content to try and narrow this down so I'll have to dig into the code more and try to figure it out.

@pr1ntr
Copy link
Contributor

pr1ntr commented Sep 22, 2018

Not sure if this helps but this happens to me when I have the following schema:

BUTTON
toPage: PAGE

PAGE
components: BUTTON

if Button has a page reference (any page, even ones that don't have it as a component) it will throw.

@zanedev
Copy link
Contributor

zanedev commented Sep 22, 2018

Thanks @pr1ntr indeed we found out that creating a new page model that wasn't called page fixed it for us but that seems weird that the slug page would be reserved or something.. Not absolutely sure yet how to avoid this in the contentful data modeling. Will keep my eye out and report back if I figure it out conclusively.

@kakadiadarpan kakadiadarpan added the type: bug An issue or pull request relating to a bug in Gatsby label Sep 27, 2018
@gatsbot gatsbot bot added the stale? Issue that may be closed soon due to the original author not responding any more. label Jan 16, 2019
@gatsbot
Copy link

gatsbot bot commented Jan 16, 2019

Old issues will be closed after 30 days of inactivity. This issue has been quiet for 20 days and is being marked as stale. Reply here or add the label "not stale" to keep this issue open!

@gatsbot
Copy link

gatsbot bot commented Jan 27, 2019

This issue is being closed due to inactivity. Is this a mistake? Please re-open this issue or create a new issue.

@gatsbot gatsbot bot closed this as completed Jan 27, 2019
@Dakuan
Copy link

Dakuan commented Feb 4, 2019

I'm also running into this. Adding a one to many content link does it.

@ankesh7
Copy link

ankesh7 commented Feb 6, 2019

Same

@jshli
Copy link

jshli commented May 29, 2019

I'm also running into this issue! I'm using a one-to-one reference, and as @cpannwitz mentions, as soon as I add a reference, it breaks - removing it removes the error. Cleaning out the cache doesn't appear to really have an effect.
The weird thing is it's inconsistent. It was breaking for me in development mode, and I just kept fiddling around with it all afternoon and suddenly, it just started working again (even though I'd done nothing of note), but when Netlify tries to build it, it breaks with the same error.

@Polyhistor
Copy link

Running into issues. definitely arising from the references

@nugoo1
Copy link

nugoo1 commented Jul 22, 2019

Hey, I has some issues and managed to fix them. I will update on this thread when I get home, no aceeas to code base atm..! Basically u have to import something to gatsby.config and if you're using any env variables, ads a GATSBY_ prefix to your environment variables

@sidharthachatterjee sidharthachatterjee added not stale and removed stale? Issue that may be closed soon due to the original author not responding any more. labels Sep 7, 2019
@nugoo1
Copy link

nugoo1 commented Sep 7, 2019

Add this to the top of gatsby-config.js

require("dotenv").config({
  path: `.env.${process.env.NODE_ENV}`,
})

And this is how my gatsby-node.js looks:

const path = require('path')

module.exports.createPages = async ({ graphql, actions }) => {
  const { createPage } = actions
  const blogTemplate = path.resolve("./src/templates/blog.js")
  const res = await graphql(`
    query {
      allContentfulBlogPost {
        edges {
          node {
            slug
          }
        }
      }
    }
  `)

  res.data.allContentfulBlogPost.edges.forEach(edge => {
    createPage({
      component: blogTemplate,
      path: `/blog/${edge.node.slug}`,
      context: {
        slug: edge.node.slug,
      },
    })
  })
}
```



My template for event page:

```
import React from "react"
import { graphql } from "gatsby"
import { documentToReactComponents } from "@contentful/rich-text-react-renderer"
import Img from "gatsby-image/withIEPolyfill"

export const query = graphql`
  query($slug: String!) {
    contentfulBlogPost(slug: { eq: $slug }) {
      title
      created(formatString: "dddd, MMMM Do YYYY")
      text {
        json
      }
      featuredImage {
        fluid(maxWidth: 600, maxHeight: 600) {
          aspectRatio
          src
          srcSet
          sizes
        }
      }
    }
    file(relativePath: { eq: "blog-post.jpg" }) {
      childImageSharp {
        fluid(maxWidth: 1920, quality: 100) {
          ...GatsbyImageSharpFluid
        }
      }
    }
  }
`

const Blog = props => {
  const options = {
    renderNode: {
      "embedded-asset-block": () => {
        return (
          <img
            alt={"alt"}
            src={props.data.contentfulBlogPost.featuredImage.fluid.src}
          />
        )
      },
    },
  }
  return (
    <Layout>
      <Slider
        sliderImage={props.data.file.childImageSharp.fluid}
        sliderTitle="Bloggin'"
        sliderSubtitle={props.data.contentfulBlogPost.title}        
        objectPosition="12% 50%"
      />
      <Heading 
          title={props.data.contentfulBlogPost.title}
          description={props.data.contentfulBlogPost.created}
      />
      <Img fluid={props.data.contentfulBlogPost.featuredImage.fluid} style={{margin:"0 auto", maxWidth:"80%", height:"100%", maxHeight:"50vh"}} objectFit="contain"/>
      <div className="blogTemplate">
        {documentToReactComponents(
          props.data.contentfulBlogPost.text.json,
          options
        )}
      </div>
      <Footer />
    </Layout>
  )
}

export default Blog
```

@wardpeet
Copy link
Contributor

Can you check if gatsby-source-contentful@2.1.35 fixed this issue. @frodd might think his fix could be related.

@ryudice
Copy link

ryudice commented Sep 15, 2019

Hi, I was having this issue and it was a circular reference, I disabled one side of the circular reference and it went away. You dont necesarrily have to remove it but you can just disable it in the response.

@omonk
Copy link
Contributor

omonk commented Oct 1, 2019

@wardpeet Thanks for that comment, that has fixed my issue.

I did a bit of debugging but the source code for this plugin is quite complex to get into so I didn't get too far, enough to understand that there is some sort of issue going on with working out referencing.

We're now seeing errors about mismatched typings, everything builds fine in netlify but wondering if there is any advice on whether or not we should be actively trying to fix this:

warn There are conflicting field types in your data.
If you have explicitly defined a type for those fields, you can safely ignore this warning message.
Otherwise, Gatsby will omit those fields from the GraphQL schema.

If you know all field types in advance, the best strategy is to explicitly define them with the `createTypes` action,
and skip inference with the `@dontInfer` directive.
See https://www.gatsbyjs.org/docs/actions/#createTypes
ContentfulSpeciality.service___NODE:
 - type: [string]
   value: [ '01316be6-eee1-57ce-a626-e8c96379bc38' ]
 - type: string
   value: 'fbe50845-a07b-5c16-9d2c-1e9c482b7f65'

The error message makes sense as we reference the service type as a multiple reference in the homepage content type and then as a single reference in another content type we use with a templated page... need to do some more digging with this one

EDIT:
Hmmm it builds fine but then my service field is not available to my schema on the content type I've recently added it to...

@gatsbot
Copy link

gatsbot bot commented Oct 22, 2019

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 gatsbot bot added the stale? Issue that may be closed soon due to the original author not responding any more. label Oct 22, 2019
@gatsbot
Copy link

gatsbot bot commented Nov 2, 2019

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!

@aprilmintacpineda
Copy link

aprilmintacpineda commented Oct 4, 2023

I'm having this problem on a fresh install of gatsby, I chose to add gatsby-source-contentful from the project initialization. I got version 8.12.0

$ gatsby develop
success compile gatsby files - 0.953s
success load gatsby config - 0.042s
success load plugins - 1.145s
success onPreInit - 0.009s
success initialize cache - 0.063s
success copy gatsby files - 0.249s
success Compiling Gatsby Functions - 0.501s
success onPreBootstrap - 0.526s

 ERROR #gatsby-source-contentful_111006  UNKNOWN

Please check if your contentTypeFilter is configured properly. Content types were filtered down to none.

not finished createSchemaCustomization - 0.825s

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale? Issue that may be closed soon due to the original author not responding any more. type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

No branches or pull requests