“gatsby-source-contentful"的插件选项无效 [英] Invalid plugin options for "gatsby-source-contentful"
问题描述
在尝试打开我通过 GitHub 分叉的项目时遇到以下错误.
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
我进行了多次编辑,但我无法处理该项目,因为我目前无法打开它.我确实有一个内容丰富的帐户,但我对 Gatsby 还很陌生,并且不知道如何为 accessToken
设置新值.
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
.
我是否需要通过 process.env
执行此操作,或者我是否完全错过了该过程?
Would I need to do this via process.env
, or am I missing the process entirely?
谢谢,感谢您的帮助.
推荐答案
我是否需要通过
process.env
执行此操作,或者我是否缺少该过程完全?
Would I need to do this via
process.env
, or am I missing the process entirely?
当然,您需要向 Gatsby 和 Contentful 提供您的访问令牌.默认情况下,Gatsby 在运行 gatsby develop
和 gatsby build
时采用 .env.development
和 .env.production
> 分别,因此您需要将凭据添加到 环境文件.
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.
首先,在您的 gatsby-node.js
中添加以下代码段,在模块导出上方:
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}`,
})
这将告诉 Gatsby 在每个运行命令中需要获取哪个文件.
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
所以,最后你的 gatsby-config.js
应该是这样的:
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,
},
},
],
}
这篇关于“gatsby-source-contentful"的插件选项无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!