我无法通过 Gatsby 连接到 Contentful
I can't connect to Contentful with Gatsby
当我尝试使用 Gatsby 连接到 Contentful 时,我收到此错误消息:
Starting to fetch data from Contentful
info Fetching default locale
ERROR
Accessing your Contentful space failed.
Try setting GATSBY_CONTENTFUL_OFFLINE=true to see if we can serve from cache.
Used options:
spaceId: "*******ed"
accessToken: "*******ed"
host (default value): "cdn.contentful.com"
environment (default value): "master"
downloadLocal (default value): false
localeFilter (default value): [Function]
forceFullSync (default value): false
pageLimit (default value): 100
useNameForId (default value): true
not finished source and transform nodes - 0.320s
我在 gatsby 中的代码-config.js :
module.exports = {
siteMetadata: {
title: `Gatsby`,
siteUrl: `http://localhost8000`,
author: '****',
},
plugins: [
{
resolve: `gatsby-source-contentful`,
options: {
spaceId: ${`process.env.CONTENTFUL_SPACE_ID`},
accessToken: ${`process.env.CONTENTFUL_ACCESS_TOKEN`},
// My code only works with this syntax ${`...`}
}
},
]
}
我看到了Brent Arias's response on this page: 。他覆盖并创建了 contentful space,并在本地重新启动了本机包含 contentful 配置的启动脚本 "rg-portfolio"。它还引用启动器中的 "contentful-data.json" 文件。
我使用 "hello world" starter,所以我自己添加了 gatsby-source-contentful 插件,它没有创建 "contentful-data.json" 文件,我没有看到任何相关信息json 文件位于 plugin's documentation。
我删除并重新创建了我的内容space,然后我重新安装了插件,但它仍然不起作用...
有什么想法吗?
我注意到您处理字符串文字的方式存在问题。
改变这个:
spaceId: ${`process.env.CONTENTFUL_SPACE_ID`},
accessToken: ${`process.env.CONTENTFUL_ACCESS_TOKEN`},
成这样(推荐):
spaceId: process.env.CONTENTFUL_SPACE_ID,
accessToken: process.env.CONTENTFUL_ACCESS_TOKEN,
或者这样:
spaceId: `${process.env.CONTENTFUL_SPACE_ID}`,
accessToken: `${process.env.CONTENTFUL_ACCESS_TOKEN}`,
当我尝试使用 Gatsby 连接到 Contentful 时,我收到此错误消息:
Starting to fetch data from Contentful
info Fetching default locale
ERROR
Accessing your Contentful space failed.
Try setting GATSBY_CONTENTFUL_OFFLINE=true to see if we can serve from cache.
Used options:
spaceId: "*******ed"
accessToken: "*******ed"
host (default value): "cdn.contentful.com"
environment (default value): "master"
downloadLocal (default value): false
localeFilter (default value): [Function]
forceFullSync (default value): false
pageLimit (default value): 100
useNameForId (default value): true
not finished source and transform nodes - 0.320s
我在 gatsby 中的代码-config.js :
module.exports = {
siteMetadata: {
title: `Gatsby`,
siteUrl: `http://localhost8000`,
author: '****',
},
plugins: [
{
resolve: `gatsby-source-contentful`,
options: {
spaceId: ${`process.env.CONTENTFUL_SPACE_ID`},
accessToken: ${`process.env.CONTENTFUL_ACCESS_TOKEN`},
// My code only works with this syntax ${`...`}
}
},
]
}
我看到了Brent Arias's response on this page: 。他覆盖并创建了 contentful space,并在本地重新启动了本机包含 contentful 配置的启动脚本 "rg-portfolio"。它还引用启动器中的 "contentful-data.json" 文件。
我使用 "hello world" starter,所以我自己添加了 gatsby-source-contentful 插件,它没有创建 "contentful-data.json" 文件,我没有看到任何相关信息json 文件位于 plugin's documentation。 我删除并重新创建了我的内容space,然后我重新安装了插件,但它仍然不起作用...
有什么想法吗?
我注意到您处理字符串文字的方式存在问题。
改变这个:
spaceId: ${`process.env.CONTENTFUL_SPACE_ID`},
accessToken: ${`process.env.CONTENTFUL_ACCESS_TOKEN`},
成这样(推荐):
spaceId: process.env.CONTENTFUL_SPACE_ID,
accessToken: process.env.CONTENTFUL_ACCESS_TOKEN,
或者这样:
spaceId: `${process.env.CONTENTFUL_SPACE_ID}`,
accessToken: `${process.env.CONTENTFUL_ACCESS_TOKEN}`,