【问题标题】:Gatsby: gatsby-source-graphql: Cannot read property 'createPageDependency' of undefinedGatsby:gatsby-source-graphql:无法读取未定义的属性“createPageDependency”
【发布时间】:2020-04-05 12:33:01
【问题描述】:

我正在为 fireblog (https://fireblogcms.com/) 构建一个 Gatsby 入门主题,它有一个 GraphQL API。所以我尝试了gatsby-source-graphql 插件,这似乎是要走的路:

当遵循此页面中的说明:https://www.gatsbyjs.org/packages/gatsby-source-graphql/ 然后访问 http://localhost:8000/___graphql 时,在我的新类型上运行 GraphQL 查询时,我遇到了这个问题 Cannot read property 'createPageDependency' of undefined

复制:

  • yarn add gatsby-source-graphql
  • 将此配置添加到gatsby-config.js
  plugins: [
    // Simple config, passing URL
    {
      resolve: "gatsby-source-graphql",
      options: {
        // This type will contain remote schema Query type
        typeName: "fireblog",
        // This is field under which it's accessible
        fieldName: "fireblog",
        // Url to query from
        url: "https://api.fireblogcms.com/graphql/blog/5de7a2934360f60004130881"
      }
    },
  //...
  ], 

转到http://localhost:8000/___graphql

并运行查询:

{
  fireblog {
    posts(last: 20) {
      edges {
        node {
          title
        }
      }
    }
  }
}

预期结果

我希望查询能够正常运行,或者出现一条错误消息来解释我接下来应该做什么才能使该查询正常工作。

实际结果

发生了什么:

{
  "errors": [
    {
      "message": "Cannot read property 'createPageDependency' of undefined",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "fireblog"
      ]
    }
  ],
  "data": null
}

gatsby info --clipboard

  System:
    OS: macOS High Sierra 10.13.6
    CPU: (8) x64 Intel(R) Core(TM) i7-4960HQ CPU @ 2.60GHz
    Shell: 5.3 - /bin/zsh
  Binaries:
    Node: 10.12.0 - ~/.nvm/versions/node/v10.12.0/bin/node
    Yarn: 1.17.3 - ~/.yarn/bin/yarn
    npm: 6.9.0 - ~/.nvm/versions/node/v10.12.0/bin/npm
  Languages:
    Python: 2.7.10 - /usr/bin/python
  Browsers:
    Chrome: 78.0.3904.108
    Firefox: 69.0.3
    Safari: 13.0.3
  npmPackages:
    gatsby: ^2.1.10 => 2.1.10
    gatsby-image: ^2.0.29 => 2.0.29
    gatsby-plugin-feed: ^2.0.13 => 2.0.13
    gatsby-plugin-google-analytics: ^2.0.14 => 2.0.14
    gatsby-plugin-html2amp: ^0.4.0 => 0.4.0
    gatsby-plugin-manifest: ^2.0.18 => 2.0.18
    gatsby-plugin-offline: ^2.0.24 => 2.0.24
    gatsby-plugin-react-helmet: ^3.0.6 => 3.0.6
    gatsby-plugin-sharp: ^2.0.21 => 2.0.21
    gatsby-plugin-typography: ^2.2.7 => 2.2.7
    gatsby-remark-copy-linked-files: ^2.0.9 => 2.0.9
    gatsby-remark-images: ^2.0.6 => 2.0.6
    gatsby-remark-prismjs: ^3.2.4 => 3.2.4
    gatsby-remark-responsive-iframe: ^2.0.9 => 2.0.9
    gatsby-remark-smartypants: ^2.0.8 => 2.0.8
    gatsby-source-filesystem: ^2.0.20 => 2.0.20
    gatsby-source-graphql: ^2.1.28 => 2.1.28
    gatsby-transformer-remark: ^2.2.5 => 2.2.5
    gatsby-transformer-sharp: ^2.1.14 => 2.1.14
  npmGlobalPackages:
    gatsby-cli: 2.8.8

【问题讨论】:

    标签: gatsby


    【解决方案1】:

    看来问题出在我的节点版本上,我上次在节点 12.4.0 上测试没问题。如果我没记错的话,我之前在节点 10.13.0

    【讨论】:

      猜你喜欢
      • 2017-06-13
      • 2019-05-12
      • 2019-12-21
      • 1970-01-01
      • 1970-01-01
      • 2020-08-01
      • 2020-03-25
      • 1970-01-01
      • 2022-11-02
      相关资源
      最近更新 更多