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-source-contentful not downloading images with downloadLocal true

See original GitHub issue

Preliminary Checks

Description

There seems to be an issue with downloading images from contentful to local if downloadLocal is true. So this config seems to have bugs:

{
      resolve: `gatsby-source-contentful`,
      options: {
        spaceId: `1234`,
        accessToken: "1234",
        downloadLocal: true,
      },
    },

I tried it twice with two different contentful repositories and two gatsby sites. Sometimes no image is local, sometimes one, sometimes all. I tried different things such as downloadLocal: false then true so the images are loaded for gatsby develop. I also tried gatsby build + serve but same issues here. The images are always accessible without localFile in graphql which means that the images are correctly configured.

This is what I get:

{
    "edges": [
        {
            "node": {
                "localFile": {
                    "id": "6f1d839c-97d8-5694-b529-ab8f735a5418"
                }
            }
        },
        {
            "node": {
                "localFile": null
            }
        },
        {
            "node": {
                "localFile": null
            }
        }
    ]
}

I have a minimal reproduction repo at https://github.com/pbizimis/gatsby-contentful-bug. I used a new contentful account so if you need to check something there let me know and I give you the credentials.

(Images are from Unsplash and the config of the repo is not sensitive because the account is a throwaway)

Thanks!

Reproduction Link

https://github.com/pbizimis/gatsby-contentful-bug

Steps to Reproduce

  1. Start it up
  2. On localhost:8000/, there should be a console log that shows an object with an array of three (you should see that at least one is null).

Expected Result

localFile data is available for all images

Actual Result

localFile data is not available for all images

Environment

System:
    OS: Linux 5.11 Ubuntu 20.04.3 LTS (Focal Fossa)
    CPU: (16) x64 Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz
    Shell: 5.8 - /usr/bin/zsh
  Binaries:
    Node: 14.17.6 - ~/.nvm/versions/node/v14.17.6/bin/node
    npm: 8.1.2 - ~/.nvm/versions/node/v14.17.6/bin/npm
  Browsers:
    Chrome: 95.0.4638.54
    Firefox: 94.0
  npmPackages:
    gatsby: ^4.1.0 => 4.1.0 
    gatsby-plugin-gatsby-cloud: ^4.1.0 => 4.1.0 
    gatsby-plugin-image: ^2.1.0 => 2.1.0 
    gatsby-plugin-manifest: ^4.1.0 => 4.1.0 
    gatsby-plugin-offline: ^5.1.0 => 5.1.0 
    gatsby-plugin-react-helmet: ^5.1.0 => 5.1.0 
    gatsby-plugin-sharp: ^4.1.0 => 4.1.0 
    gatsby-source-contentful: ^6.1.0 => 6.1.0 
    gatsby-source-filesystem: ^4.1.0 => 4.1.0 
    gatsby-transformer-sharp: ^4.1.0 => 4.1.0 
  npmGlobalPackages:
    gatsby-cli: 4.1.0

Config Flags

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:16

github_iconTop GitHub Comments

5reactions
afladmarkcommented, Dec 20, 2021

I’ve tested this fix via @next on our builds and confirm it resolves our issue. Thank you so much for fixing this @wardpeet! We can finally upgrade to Gatsby 4!

1reaction
afladmarkcommented, Nov 23, 2021

As with @julrich we also use Contentful Assets local download option via a custom resolver (to enable custom localization fallbacks to English images). In Gatsby Cloud, we get empty localFile nodes 100% of the time. On local develop it mostly/often works and with local builds it often succeeds. After a gatsby clean it generally fails. We couldn’t build in any case until we moved the resolvers from createResolvers to createSchemaCustomization via buildObjectType, but we’re basically dead in the water with Gatsby 4 at this point as well due to this issue. We have updated all our logic to reflect the changes introduced in the fix PR as well. Prior to that it was completely broken in all environments.

Read more comments on GitHub >

github_iconTop Results From Across the Web

gatsby-source-contentful
When you set downloadLocal: true in your config, the plugin will download and cache Contentful assets to the local filesystem. There are two...
Read more >
How to retrieve asset in Gatsby Source Contentful? (not images)
This will download the asset locally and should provide a valid URL for static distribution. { resolve: `gatsby-source-contentful`, options: { ...
Read more >
Gatsby Changelog | 5.3.0
In PR #36623 we fixed this behavior and any node changes (either by changing local files or through webhook updates) will be reflected...
Read more >
Building Rise of the Robots with Gatsby and Contentful
Here's a video, it's just under six minutes and it'll walk you through, in real time, how to build a Gatsby site from...
Read more >
10 Gatsby Plugins for Contentful You Should Know About
This is where gatsby-source-contentful comes into play. ... title images with Gatsby using Contentful since they are not part of the content ...
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