I'm encountering the following error when attempting to open a project I forked via GitHub.
success open and validate gatsby-configs - 0.492s
ERROR #11331 PLUGIN
Invalid plugin options for "gatsby-source-contentful":
- "accessToken" is required
not finished load plugins - 6.220s
I've made several edits but am unable to work on the project as I'm unable to open it at the moment. I do have a contentful account, but am fairly new to Gatsby and am unaware of how to set a new value for the accessToken
.
Would I need to do this via process.env
, or am I missing the process entirely?
Thank you, any help is appreciated.
Gatsby is a modern static-site generator that has revamped the way static websites are being built. It incorporates React, Node. js, and GraphQL to create stunning and blazing-fast websites.
Learn how to easily build a GatsbyJS website powered by Contentful. Working with React. js and having an emphasis on speedy performance, GatsbyJS is a popular static site generator that allows you to connect your web projects to a variety of APIs and data sources; including Contentful's content infrastructure.
Would I need to do this via
process.env
, or am I missing the process entirely?
Absolutely, you need to provide to Gatsby and Contentful your access tokens. Gatsby, by default, takes the .env.development
and .env.production
when running gatsby develop
and gatsby build
respectively, so you will need to add the credentials to the environment files.
First of all, add the following snippet in your gatsby-node.js
, above the module exportation:
require("dotenv").config({
path: `.env.${process.env.NODE_ENV}`,
})
This will tell Gatsby which file needs to be taken in each running command.
The next step is to fill the environment files, in both of them add:
CONTENTFUL_ACCESS_TOKEN=123456
CONTENTFUL_SPACE_ID=78910
So, finally your gatsby-config.js
should look like:
// In your gatsby-config.js
module.exports = {
plugins: [
{
resolve: `gatsby-source-contentful`,
options: {
spaceId: process.env.CONTENTFUL_SPACE_ID,
accessToken: process.env.CONTENTFUL_ACCESS_TOKEN,
},
},
],
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With