Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid plugin options for "gatsby-source-contentful"

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.

like image 260
Blake Lucey Avatar asked Mar 14 '21 02:03

Blake Lucey


People also ask

What is Gatsby plugin?

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.

What is Contentful Gatsby?

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.


1 Answers

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,
      },
    },
  ],
}
like image 70
Ferran Buireu Avatar answered Sep 25 '22 16:09

Ferran Buireu