wordpress - Gatsby 插件 Gatsby-Source-Wordpress 出错

标签 wordpress reactjs gatsby

我正在尝试设置我的第一个 gatsby + wordpress 网站。我正在关注this教程。

我让网站运行起来,但在我应该从 WP 获取数据的时候我陷入了困境。我添加了 Gatsby-Source-Wordpress 插件。我重新启动网站后,它抛出此错误:

success open and validate gatsby-configs - 0.102 s
success load plugins - 0.631 s
success onPreInit - 0.019 s
success initialize cache - 0.053 s
success copy gatsby files - 0.161 s
success onPreBootstrap - 0.040 s
info Creating GraphQL type definition for File

Path: /wp-json
The server response was "404 Not Found"

 ERROR #11321  PLUGIN

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

Cannot read property 'data' of undefined



  TypeError: Cannot read property 'data' of undefined

  - fetch.js:141 fetch
    [gatsby-wordpress]/[gatsby-source-wordpress]/fetch.js:141:21

  - next_tick.js:68 process._tickCallback
    internal/process/next_tick.js:68:7


warn The gatsby-source-wordpress plugin has generated no Gatsby nodes. Do you need it?
success source and transform nodes - 0.327 s
success building schema - 0.404 s
success createPages - 0.019 s
success createPagesStatefully - 0.090 s
success onPreExtractQueries - 0.022 s
success update schema - 0.079 s
success extract queries from components - 0.595 s
success write out requires - 0.103 s
success write out redirect data - 0.032 s
success Build manifest and related icons - 0.263 s
success onPostBootstrap - 0.308 s
⠀
info bootstrap finished - 6.617 s
⠀
success run static queries - 0.105 s — 3/3 36.11 queries/second
success run page queries - 0.044 s — 5/5 230.97 queries/second
 DONE  Compiled successfully in 4851ms                                                           10:46:42 AM
⠀
You can now view gatsby-starter-default in the browser.
⠀
  http://localhost:8000/
⠀
View GraphiQL, an in-browser IDE, to explore your site's data and schema
⠀
  http://localhost:8000/___graphql
⠀
Note that the development build is not optimized.
To create a production build, use npm run build
⠀
ℹ 「wdm」:
ℹ 「wdm」: Compiled successfully.

我使用 Mamp 在本地运行 WP,我可以在此处看到 JSON 数据:http://localhost:8888/GatsbyWP/wp-json/

这是我的 gatsby-config.js 文件:

module.exports = {
  siteMetadata: {
    title: `Gatsby wordpress test`,
    description: `Testing...`,
    author: `@gatsbyjs`,
  },
  plugins: [
    `gatsby-plugin-react-helmet`,
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `images`,
        path: `${__dirname}/src/images`,
      },
    },
    `gatsby-transformer-sharp`,
    `gatsby-plugin-sharp`,
    {
      resolve: `gatsby-plugin-manifest`,
      options: {
        name: `gatsby-starter-default`,
        short_name: `starter`,
        start_url: `/`,
        background_color: `#663399`,
        theme_color: `#663399`,
        display: `minimal-ui`,
        icon: `src/images/gatsby-icon.png`,
      },
    },
    {
      resolve: "gatsby-source-wordpress",
      options: {

        baseUrl: `localhost:8888`,

        protocol: `http`,

        hostingWPCOM: false,

        useACF: true,
      },
    },
    `gatsby-plugin-sitemap`,
  ],
}

我被困住了,不知道现在该怎么办。我发现其他人也遇到了与此类似的问题,但没有找到任何好的答案或方向来尝试解决我的问题。

提前致谢!

最佳答案

gatsby-source-wordpress的选项要求...

the base URL of the Wordpress site without the trailing slash and the protocol. This is required.
Example : 'gatsbyjsexamplewordpress.wordpress.com' or 'www.example-site.com'

module.exports = {
  siteMetadata: {
    title: `Gatsby wordpress test`,
    description: `Testing...`,
    author: `@gatsbyjs`,
  },
  plugins: [
    {
      resolve: "gatsby-source-wordpress",
      options: {
        baseUrl: `localhost:8888/GatsbyWP`,
        protocol: `http`,
        hostingWPCOM: false,
        useACF: true,
      },
    },
  ],
}

关于wordpress - Gatsby 插件 Gatsby-Source-Wordpress 出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57323062/

相关文章:

php - 获取并在 Woocommerce 单一产品页面上显示税率

reactjs - Bitbucket 管道无法推送到 heroku

javascript - Next Js & Typescript - 类型示例中不存在属性 setState

javascript - 如何将 graphQL 查询转换为 React 组件?

css - WP 如何使用 CSS 类自定义特定的缩略图大小

Wordpress 为用户登录生成 WP_Error 对象?

javascript - 单击鼠标后,在进入下一页之前在 div 内运行脚本

reactjs - 在 React JS 中更新数组时 this.setState 和 this.state 的问题

GatsbyJS 中的 GraphQL 过滤器

nuxt.js - 当所有人都可以生成静态站点时,为什么我会选择 Gridsome/Gatsby 而不是 Nuxt/Next?