Any idea, what could have gone wrong with contentful.
I am using
"gatsby-source-contentful": "^1.3.31",
For the past couple of hours, I am seeing the below error on all my contentful projects.
gatsby develop
success delete html and css files from previous builds — 0.009 s
success open and validate gatsby-config.js — 0.005 s
success copy gatsby files — 0.018 s
success onPreBootstrap — 0.676 s
⡀ source and transform nodesStarting to fetch data from Contentful
Fetching default locale
⠈ source and transform nodes[warning] Connection error occurred. Waiting for 2092 ms before retrying...
⢀ source and transform nodes[warning] Connection error occurred. Waiting for 2676 ms before retrying...
⢀ source and transform nodes[warning] Connection error occurred. Waiting for 3402 ms before retrying...
⠐ source and transform nodes[warning] Connection error occurred. Waiting for 4551 ms before retrying...
⡀ source and transform nodes[warning] Connection error occurred. Waiting for 6239 ms before retrying...
⢀ source and transform nodesAccessing your Contentful space failed. Perhaps you're offline or the spaceId/accessToken is incorrect.
The contentful api status is green as seen here https://www.contentfulstatus.com/
Perhaps you're offline or the spaceId/accessToken is incorrect
I had this same issue when I hosted my site on Netlify but forgot to include the environment variables for Contentful's access token.
Have you checked your config.js to make sure you're using the correct access tokens and space id?
// In your gatsby-config.js
plugins: [
{
resolve: `gatsby-source-contentful`,
options: {
spaceId: `your_space_id`,
accessToken: `your_access_token`,
},
},
];
If used environment variables instead such as dotenv instead of hardcoding it, make sure that you're accessing those environment variables properly.
I had this same issue when my environment variables were actually returning null.
Here's my code for using dotenv.
let env = process.env.NODE_ENV || 'development';
// This adds dotenv (for storing environment variables) to gatsby
require('dotenv').config({path: `./.env.${env}`});
module.exports = {
siteMetadata: {
title: 'Gatsby Default Starter',
},
plugins: [
'gatsby-plugin-react-helmet',
{
resolve: `gatsby-source-contentful`,
options: {
spaceId: `${process.env.CONTENTFUL_SPACE_ID}`,
accessToken: `${process.env.CONTENTFUL_ACCESS_TOKEN}`,
},
},
]
}
and in your .env.development file, place your private keys
// .env.development
CONTENTFUL_SPACE_ID = 'blablablabla'
CONTENTFUL_ACCESS_TOKEN = 'blablablabla'
If none of it works, delete your cache.
Disclaimer: I have no clue how the cache works but whenever I have errors that wasn't there 1 build ago, (usually after changing my contentful schema) it solves the issue.
@daydream05 thanks for your inputs. But all that was fine for me. The environment variable was coded properly across these projects. I had a couple of contentful projects using different space ids and all of them were getting stuck at the same place. The contentful API was up. My internet connection was working properly .... It was weird.
So I unleashed the final weapon and rebooted my laptop. Lo & behold, it all works fine again!
@Jaikant Did you figure out what was wrong? I have the same problem on a Mac. This is the only GitHub issue I found with the exact same problem (unexplainable connection error solved by reboot - deleting cache does not help). When working on the same Gatsby project from my Windows laptop, it does never happen, only on Mac (about 1-2 times a day). Thanks!
Deleted my .cache and it worked for me.
@adrianwe No not sure about this. Never happened again to me.
@Jaikant Okay, thanks for your reply!
I'am getting the same error on my Mac and rebooting, clearing cache, nor hard coding space id and access token did not resolve it.
I had similar a similar issue recently. I wanted to use a different environment and in the API Key setting of my second environment wasn't check.
Hope that help someone :)
If this is still persisting for anyone, or someone comes across this, I found a solution. I installed dotenv to my project then imported it require("dotenv").config() using that and put my .env variables in their normal place.
I'm not sure if this is the correct solution, but my errors have gone away. Hope it helps.
Confirming this issue is still reproducible on Macs when using the contentful guide command of contentful-cli. Contentful config options are logging correctly prior to error, no recommended solution has resolved the issue on Mac.
Several Contentful-cli docs reference this project, it needs to run to confirm basic operations for the CLI / play "which one of these is not like the other".
Fixed: The version of this starter project that installs from the contentful guide command fails as described previously. However, if you clone the project directly and run through the setup after installing dependencies (I used yarn), it runs.
You may also need to adjust your node version using NVM. To install gatsby-cli, I downgraded to 10.15.3
Note: A difference between the contentful guide build and direct download / setup I noticed after the fact:
Most helpful comment
If used environment variables instead such as dotenv instead of hardcoding it, make sure that you're accessing those environment variables properly.
I had this same issue when my environment variables were actually returning null.
Here's my code for using dotenv.
and in your
.env.development file, place your private keys