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] Gatsby fails to connect to other Contentful environments than master

See original GitHub issue

Description

For gatsby-source-contentful version 2.1.45 and newer, when trying to access content from a Contentful space in another environment than master (for instance development) with an access token that is only allowed for this environment, but not also for master, Gatsby fails to connect with the message ‘Accessing your Contentful space failed.’.

It connects successfully if the access token also allows access to the master environment, but I need to have individual access tokens for each environment. This behavior only occurs since gatsby-source-contentful version 2.1.45, including the most recent version 2.3.46. For older versions up to 2.1.44, it works fine.

Steps to reproduce

  • create Contentful space with two environments, e.g. master and development
  • create an access token with only access to the development environment
  • install the most recent versions of gatsby and gatsby-source-contentful
  • setup gatsby-source-contentful to connect to the development environment with the access token
  • run gatsby develop

Expected result

Gatsby runs correctly.

Actual result

With gatsby-source-contentful version 2.1.45 and newer, it crashes with this error message:

Accessing your Contentful space failed.
Try setting GATSBY_CONTENTFUL_OFFLINE=true to see if we can serve from cache.

Used options:
spaceId: "*********dbd"
accessToken: "***************************************SnLg"
environment: "development"
host: "cdn.contentful.com"
downloadLocal (default value): false
localeFilter (default value): [Function]
forceFullSync (default value): false
pageLimit (default value): 100
useNameForId (default value): true

not finished source and transform nodes - 0.422s
error Command failed with exit code 1.

Environment

  System:
    OS: macOS Mojave 10.14.6
    CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 12.16.2 - /usr/local/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.14.4 - /usr/local/bin/npm
  Languages:
    Python: 2.7.16 - /usr/bin/python
  Browsers:
    Chrome: 80.0.3987.132
    Firefox: 79.0
    Safari: 13.1.2
  npmPackages:
    gatsby: ^2.24.60 => 2.24.60
    gatsby-plugin-manifest: ^2.0.19 => 2.3.3
    gatsby-plugin-meta-redirect: ^1.1.1 => 1.1.1
    gatsby-plugin-react-helmet: ^3.0.7 => 3.2.1
    gatsby-plugin-react-svg: ^2.1.1 => 2.1.2
    gatsby-plugin-sass: ^2.0.10 => 2.2.1
    gatsby-source-contentful: ^2.3.46 => 2.3.46

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
axe312gercommented, Oct 2, 2020

I found an internal ticket confirming this issue.

Looks like for now your access token needs to have access to master environment, even when content is loaded from a different environment.

I will keep u posted.

1reaction
axe312gercommented, Mar 29, 2021

This was fixed in v4.7.0. Closing

Read more comments on GitHub >

github_iconTop Results From Across the Web

Accessing your Contentful space failed with gatsby-source ...
Setting environment to "master" and removing it completely; Wrapping the env vars in template literals (suggested on an old github issue). I ...
Read more >
gatsby-source-contentful
How to use. First, you need a way to pass environment variables to the build process, so secrets and other secured data aren't...
Read more >
How Contentful Helps Us Manage Our Static Content
We require different environments for our content. An environment is how contentful manages version control. By default, a master environment is ...
Read more >
Get started with Contentful
Create a space, add sample content, and deploy a Gatsby site. See how Contentful works with the latest web technologies to power content....
Read more >
Making a Static Website with Gatsby, Contentful, and Netlify
Finally, modify gatsby-source-contentful's options in gatsby-config.js to use the environment variables instead of hard-coded values:
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