Invalid plugin options for "gatsby-source-contentful"
Asked Answered
S

2

9

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.

Sodality answered 14/3, 2021 at 2:37 Comment(0)
M
10

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,
      },
    },
  ],
}
Minimum answered 14/3, 2021 at 11:54 Comment(0)
V
1

You may not be having .env file at application root.

Virgo answered 3/3, 2023 at 5:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.