Intermittent build failure (gatsby + netlify cms)

netlify site name: marlinhawk-website

We own a website hosted on netlify, using gatsby and netlify cms. The build works, but randomly fails once in a while (maybe 50% of the time). This is not due to package version, or content. Building the same (identical) version twice might result in both failure and success.

When a build fails, rebuilding it might pass the issue. Clearing cache and rebuilding always works. But obviously I want to be able to continue using the build cache. That is not to say that a cached build always fails. It does work, it’s just that randomly it fails.

When it fails, the error is always the same:

error There was an error in your GraphQL query:
Field “document” must not have a selection since type “String” has no subfields.
This can happen if you e.g. accidentally added { } to the field “document”. If you didn’t expect “document” to be of type “String” make sure that your input source and/or plugin is correct.
failed extract queries from components - 0.701s

The query is actually correct (like I said, the build succeed more often than not). The content is also correct (without changing content, build can both fail and succeed, after retrying to build the same version of code + content)

I have been trying to solve this issue for months, to no avail. I have tried working with the gatsby inferred types, to make sure the query doesn’t fail to build. I have tried tweaking the config, to no avail. I am trying upgrading all the packages, to see if that can help. But I feel this is an issue with how the build are cached.

I know there is a way to reproduce the build locally using docker images. I haven’t tried that yet, but I was wondering if anyone has had a similar issue before, or if anyone has any ideas on what to try/look for.

I have obviously check all the documentation and support posts about fixing build issues. This is not a typical “my build fail”, but rather “my build fails randomly”, which is very different.

I forgot to mention, I haven’t faced this issue when building locally…

hi there wintercircle, could you share which versions of netlify cms, gatsby etc you are using?

gatsby: ^2.14.2 => 2.19.12
gatsby-background-image: ^0.8.14 => 0.8.19
gatsby-image: ^2.2.9 => 2.2.40
gatsby-plugin-canonical-urls: ^2.1.20 => 2.1.20
gatsby-plugin-create-client-paths: ^2.1.7 => 2.1.22
gatsby-plugin-google-analytics: ^2.1.19 => 2.1.35
gatsby-plugin-lead-forensics: 0.0.2 => 0.0.2
gatsby-plugin-linkedin-insight: ^1.0.1 => 1.0.1
gatsby-plugin-local-search: ^1.1.0 => 1.1.0
gatsby-plugin-manifest: ^2.2.5 => 2.2.41
gatsby-plugin-netlify-cms: ^4.1.7 => 4.1.38
gatsby-plugin-offline: ^2.2.6 => 2.2.6
gatsby-plugin-react-helmet: ^3.1.3 => 3.1.3
gatsby-plugin-robots-txt: ^1.5.0 => 1.5.0
gatsby-plugin-root-import: ^2.0.5 => 2.0.5
gatsby-plugin-sharp: ^2.2.12 => 2.4.5
gatsby-plugin-sitemap: ^2.2.27 => 2.2.27
gatsby-plugin-styled-components: ^3.1.3 => 3.1.19
gatsby-remark-copy-linked-files: ^2.1.9 => 2.1.9
gatsby-remark-images: ^3.1.16 => 3.1.16
gatsby-remark-relative-images: ^0.2.3 => 0.2.3
gatsby-source-filesystem: ^2.1.9 => 2.1.9
gatsby-transformer-remark: ^2.6.14 => 2.6.14
gatsby-transformer-sharp: ^2.2.6 => 2.3.14
gatsby-cli: 2.8.29
gatsby-plugin-lead-forensics: 0.0.2

thank you, @WinterCircle ! i don’t see anything odd jump out at me, so I am actually going to take this to a meeting we have scheduled soon with some of the folks who know gatsby a lot better than i do.

I’ll report back what i find out!

hi again @WinterCircle! I chatted with our gatsby pro the other day, and the current working hypothesis is that you might have a race condition happening here, which could explain the intermittent nature of this bug. This is not uncommon when using tools like gatsby and querying api’s and things, as the tool may expect data to be there that isn’t.

I encourage you to chat with the #netlify-cms people (in fact I am going to move your thread there) and see if they have ideas. If that doesn’t yield anything, please post a code sample if you can and we can take a closer look.

Hi all :wave: Thanks for tagging me @perry

@WinterCircle, I think your attempt of working with inferred type is a very good place to start.
I’ve usually seen similar errors due to the automatic type inferences Gatsby does when sourcing files and transforming them into queryable data. Sometimes the type inference fails to detect the correct type thus resulting in a query error.

Can you share the repo/some code that describes?

  1. The query that fails
  2. Where the data for that query is sourced from (e.g. a markdown file with the document field).
  3. The gatsby-config.js file

I’ve created an issue with gatsby (which was closed). It has all the details

the gatsby-config is here:

the document field is defined like this:

Here’s an example of a markdown file with the document field defined:

and the query:

Hi @WinterCircle, thank you for sharing the information and sorry for the delayed response.
The best way I know for dealing with such issues is to store assets relative to their content as Gatsby works better that way.
This is documented here and here.

The TLDR is to configure your collection as such:

  - name: 'my-type'
    label: 'My type'
    folder: 'src/content/my-folder'
    create: true
    media_folder: ''
    public_folder: ''
      - {
          label: 'Template Key'
          name: 'templateKey'
          widget: 'hidden'
          default: 'my-template-type'
      - { label: 'Document', name: 'document', widget: 'file', required: true }

can you try that and see if it solves the issue?

1 Like

Thanks @erez. I have updated all the software stack in the meantime. Since using gatsby 3.5.0 (and all the updated plugins) the build doesn’t seem to have any issues so far (without changing anything else)

1 Like