Gatsby build issues after migration to latest packages version

Hey guys, we are expecting a weird issues after migration to the latest contentful plugin:

"gatsby-source-contentful": "^8.12.3",

Here the full list of packages:

"babel-plugin-styled-components": "^2.0.2",
    "dotenv": "^16.0.0",
    "gatsby": "^5.12.7",
    "gatsby-plugin-algolia": "^1.0.3",
    "gatsby-plugin-google-analytics": "^5.12.0",
    "gatsby-plugin-image": "^3.12.2",
    "gatsby-plugin-manifest": "^5.12.2",
    "gatsby-plugin-preload-fonts": "^4.12.0",
    "gatsby-plugin-react-helmet": "^6.12.0",
    "gatsby-plugin-remove-serviceworker": "^1.0.0",
    "gatsby-plugin-sharp": "^5.12.2",
    "gatsby-plugin-sitemap": "^6.12.2",
    "gatsby-plugin-styled-components": "^6.12.0",
    "gatsby-remark-images-contentful": "^6.12.1",
    "gatsby-source-contentful": "^8.12.3",
    "gatsby-source-filesystem": "^5.12.0",
    "gatsby-transformer-remark": "^6.12.2",
    "gatsby-transformer-sharp": "^5.13.0-next.0",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-helmet": "^5.2.1",
    "react-instantsearch-dom": "^6.25.0",
    "react-intersection-observer": "^9.1.0",
    "react-share": "^4.4.0",
    "styled-components": "^5.3.3"

Node version is 18.0.0

We have 2 projects

please see attached IDs:

  • 342a7324-1190-4579-a8ec-deb2970a1441
  • 9a4caf1b-5820-4a50-9203-e45573aae8e7

Here a few failed builds:

please notice that some errors are saying that conditional check doesn’t work correct but that seems like a bug or something like that because on local machine and even if you will trigger build(with cache clean) again this issue doesn’t exist.

Thanks in advance for your help!

Hi there,

Thanks for reaching out! From reviewing the build logs, it looks like the primary issue here is builds failing due to issues building the static HTML for the site, e.g:

3:46:55 PM: failed Building static HTML for pages - 2.600s
3:46:55 PM: error Building static HTML failed for path "/"

In the vast majority of cases, these errors are caused by a JS issue in the template/component that is responsible for generating the page (which from the stack trace here looks to be FeaturedPosts):

3:46:55 PM:   WebpackError: TypeError: Cannot read properties of null (reading "length")
3:46:55 PM:   
3:46:55 PM:   - FeaturedPosts.js:81 
3:46:55 PM:     lc/src/components/FeaturedPosts.js:81:22

Whether the issue is replicable locally typically depends on the build command you’re using. When running Gatsby in development mode (gatsby develop), Gatsby will often bypass these types of errors during the build and later display them in the UI (they should be present when navigating to / or whichever path is displayed in the error message). When running gatsby build locally, we would expect the same error to be thrown during the build. Let me know!

hi Marcus, thanks for the reply.

Please take a look this build:

and next one which was triggered manually in netlify without any code or cms updates:

first one failed and second one is deployed successfully, any ideas why?

Thanks for following up! These kinds of intermittent failures on CMS data updates are sometimes indicative of there being an issue with certain kinds of content; do you see the errors when updating a particular content type, for instance?

While you might be able to just add some optional chaining here, e.g: faqItems?.length, identifying why faqItems is null may require confirming any similarities in the content models in Contentful for the entries that are throwing these errors.

I’d still suggest debugging this locally in development as a starting point and confirming whether there are any errors in the UI/console at the routes in the error logs. It looks like the last few dozen builds have been successful, but if you think this to be a bug in the source plugin, a minimal reproduction is also the best way to help our team get to the bottom of what might be going on here. Thanks again!