【问题标题】:ERROR #11321 PLUGIN while building in Gatsby在 Gatsby 中构建时出现错误 #11321 PLUGIN
【发布时间】:2021-12-06 21:36:40
【问题描述】:

我正在尝试学习和编写我的第一个 GatsbyJs 作品集,但在构建此入门时遇到错误:https://www.gatsbyjs.org/starters/smakosh/gatsby-portfolio-dev/

仍然没有触及任何一行代码... 尝试再次删除 node_modules 和 npm install 但同样的错误。


"gatsby-source-graphql" threw an error while running the sourceNodes lifecycle:

Response not successful: Received status code 401



  ServerError: Response not successful: Received status code 401
  
  - index.js:23 Object.exports.throwServerError
    [gatsby-portfolio-dev]/[apollo-link-http-common]/lib/index.js:23:17
  
  - index.js:48 
    [gatsby-portfolio-dev]/[apollo-link-http-common]/lib/index.js:48:21
  
  - task_queues.js:97 processTicksAndRejections
    internal/process/task_queues.js:97:5
  

not finished source and transform nodes - 1.135s

【问题讨论】:

    标签: gatsby netlify


    【解决方案1】:

    由于您的gatsby-config.js (line 25) 中有一些环境变量,因此您的项目无法运行。

    {
          resolve: 'gatsby-source-graphql',
          options: {
            typeName: 'GitHub',
            fieldName: 'github',
            url: 'https://api.github.com/graphql',
            headers: {
              Authorization: `bearer ${process.env.GATSBY_PORTFOLIO_GITHUB_TOKEN}`, // here
            },
            fetchOptions: {},
          },
        },
    

    基本上,您不能连接到 GitHub 来收集信息,并且他们的 API 会抛出 401 错误(未经授权)。

    环境变量包含idstokens 和其他关键(和私有)数据,这些数据允许您连接到某些外部 API(在本例中为 GitHub),并且它们不得上传到公共存储库中(出于显而易见的原因) 这就是启动器不提供此信息的原因。您应该自行将其添加到您的项目中。查看GitHub's documentation 获取您自己的 API 令牌。

    如果您检查您正在尝试运行的启动器的CodeSandbox,它们有一个空的.env.development 文件,所有这些变量都应该在其中。

    更多信息,请查看Gatsby's documentation about Environment Variables

    【讨论】:

      【解决方案2】:

      我有同样的问题。正如盖茨比文档中所说:

      您需要在您的 wordpress 中安装以下 wordpress 插件 实例https://wordpress.org/plugins/wp-rest-api-v2-menus/

      https://www.gatsbyjs.com/plugins/gatsby-source-wordpress-menus/

      【讨论】:

        猜你喜欢
        • 2023-01-08
        • 2021-07-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-08-17
        • 2019-07-12
        • 1970-01-01
        • 2013-03-17
        相关资源
        最近更新 更多