我将 Gatsby 与 Netlify CMS 一起使用,并在 Netlify CMS 中预览模板时遇到了问题。
有一个按预期工作的索引页面组件。它从 markdown 和 frontmatter 获取数据,并与 Netlify CMS 小部件链接,并且有特色的帖子组件通过useStaticQuery
钩子获取其数据。
但是,一旦我进入Netlify 管理员中的索引页面预览模板,我会得到:
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 数据呈现主页,该组件通过Netlify Admin 中的挂钩从/posts
目录中获取其数据。useStaticQuery
复制回购可以在这里找到