Accessing your Contentful space failed with gatsby-source-contentful

天涯浪子 提交于 2020-05-29 06:49:07

问题


gatsby: 2.20.8
gatsbh-source-contentful: 2.2.5

I've verified my spaceId and accessToken are correct, and I've verified that these keys have access to my Contentful development environment. I've tried:

  • Enabling GATSBY_CONTENTFUL_OFFLINE
  • Deleting the .cache directory
  • Deleting node_modules
  • Setting environment to "master" and removing it completely
  • Wrapping the env vars in template literals (suggested on an old github issue)

I keep getting this error. Any ideas?

ERROR 

Accessing your Contentful space failed.
Try setting GATSBY_CONTENTFUL_OFFLINE=true to see if we can serve from cache.

Used options:
spaceId: "*********z1u"
accessToken: "*****************************************vMI'"
environment: "development"
host (default value): "cdn.contentful.com"
downloadLocal (default value): false
localeFilter (default value): [Function]
forceFullSync (default value): false
pageLimit (default value): 100
useNameForId (default value): true

And here's my code from gatsby-config.js

{
  resolve: `gatsby-source-contentful`,
  options: {
    spaceId: process.env.CONTENTFUL_SPACE_ID,
    accessToken: process.env.CONTENTFUL_ACCESS_TOKEN,
    environment: process.env.CONTENTFUL_ENVIRONMENT,
  },
},

回答1:


As I stated in my comment to your question, I was suspicious this had something to do with a discrepancy between the Contentful models that my Gatsby build expected, and what models were actually in the Contentful space. Acting on that I decided to delete my Contentful space entirely and re-create it. I then re-ran the automation script, which came with the rg-portfolio repo, that is responsible for creating all my initial content models. This had been part of the instructions for rg-portfolio.

contentful space --space-id xxxxxxxxx0b9 import --content-file contentful-data.json

The script completed successfully, no errors - only warnings about rate limiting.

When I then finally retried gatsby develop it worked!!!

Post-game analysis.

Part of the reason I suspected this Contentful "model discrepancy" issue was because when I first ran that contentful-data.json script:

  1. It was running against a Contentful space that already had some unrelated content models in it.
  2. It gave actual errors that made me wonder if it really had worked properly.

So there was a lot of room for me to believe there was something just "wrong" with the model(s) in that Contentful space.




回答2:


Not sure if you got it working in the meantime but I had this same issue and found this on Github https://github.com/gatsbyjs/gatsby/issues/19392 that is what you and I are having.

Apparently, in newer versions of gatsby-source-plugin it requires the key to have access to the master environment as well (which is ridiculous imo).

After giving the key access to master environment it started working.



来源:https://stackoverflow.com/questions/60892938/accessing-your-contentful-space-failed-with-gatsby-source-contentful

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!