呈现StaticQuery的Gatsby和Netlify CMS预览错误

时间:2019-11-17 22:27:48

标签: javascript graphql gatsby netlify netlify-cms

我在Netlify CMS中使用Gatsby,并遇到了Netlify CMS中预览模板的问题。

有一个index page component可以正常工作。它从markdown和frontmatter获取数据,并与 Netlify CMS窗口小部件,有featured posts组件可通过useStaticQuery挂钩获取其数据。

但是一旦我在Netlify管理员中进入index page preview template,我就会得到:

Error: The result of this StaticQuery could not be fetched.

This is likely a bug in Gatsby and if refreshing the page does not fix it, please open an issue in https://github.com/gatsbyjs/gatsby/issues
useStaticQuery
./.cache/gatsby-browser-entry.js:1
> 1 | import React from "react"
  2 | import PropTypes from "prop-types"
  3 | import Link, {
  4 |   withPrefix,
View compiled
_default
./src/components/common/FeaturedPosts.js:1
> 1 | import React from 'react'
  2 | import v4 from 'uuid'
  3 | import { useStaticQuery, graphql } from "gatsby"
  4 | 
View compiled
▶ 28 stack frames were collapsed.

我的目标是使用来自Netlify CMS的markdown和frontmatter数据以及功能强大的博客列表组件来呈现homepage,该组件通过Netlify Admin中的/posts钩子从useStaticQuery目录中获取数据。< / p>

可以找到here

1 个答案:

答案 0 :(得分:0)

Graphql查询表明Gatsby进程将无法在netlify-cms预览中运行。通常,gatsby和netlify-cms在构建过程中使用单独的webpack实例。至少这是在gatsby-plugin-netlify-cms中完成的。

如果您确实需要访问为静态查询提取的数据,但是您将无法保留与导入原始JSON文件相同的代码,请查看此问题。  https://stackoverflow.com/a/58944342/157601