Error: The result of this StaticQuery could not be fetched

Error: The result of this StaticQuery could not be fetched

概览

我用的是gatsby环境

由于gatsby中使用了graphql,所以使用了useStaticQuery

在开发环境下运行正常(gatsby develop),在搭建后的环境下(gatsby build && gatsby serve),出现了如题的错误。

错误文本

错误:无法获取此 StaticQuery 的结果。

这可能是 Gatsby 中的错误,如果刷新页面无法解决问题,请在 https://github.com/gatsbyjs/gatsby/issues

中提出问题

错误代码

const data = useStaticQuery(
    graphql`
      query {
        allArticle(sort: { order: DESC, fields: updatedAt___seconds }) {
          edges {
            node {
              category
              id
              thumbnail
              title
              createdAt {
                seconds
              }
            }
          }
        }
        allRanking {
          edges {
            node {
              id
              category
              title
              thumbnail
            }
          }
        }
      }
    `
  )

※ 因为在secret模式下可以正常使用,不知道是不是缓存有问题

我试过的

删除盖茨比

  1. $ yarn remove gatsby
  2. $ rm -rf node_modules
  3. $ yarn install
  4. $ gatsby build && gatsby serve

执行 gatsby 清理命令

  1. $ gatsby clean

更改组件名称和文件

https://github.com/gatsbyjs/gatsby/issues/24902#issuecomment-847926225

删除.cache文件

我的环境

OS : 苹果机OS

package.json

"dependencies": {
    "firebase": "^8.6.7",
    "gatsby": "^3.6.2",
    "gatsby-plugin-advanced-sitemap": "^2.0.0",
    "gatsby-plugin-clarity": "^1.0.0",
    "gatsby-plugin-dark-mode": "^1.1.2",
    "gatsby-plugin-google-adsense": "^1.1.3",
    "gatsby-plugin-google-gtag": "^3.7.1",
    "gatsby-plugin-manifest": "^3.6.0",
    "gatsby-plugin-offline": "^4.6.0",
    "gatsby-plugin-react-helmet": "^4.6.0",
    "gatsby-plugin-twitter": "^3.12.0",
    "gatsby-source-filesystem": "^3.7.1",
    "react": "^17.0.1",
    "react-calendar-heatmap": "^1.8.1",
    "react-copy-to-clipboard": "^5.0.4",
    "react-dom": "^17.0.1",
    "react-helmet": "^6.1.0",
    "react-lazyload": "^3.2.0",
    "react-markdown": "5.0.3",
    "react-scroll": "^1.8.2",
    "react-slick": "^0.28.1",
    "react-syntax-highlighter": "^15.4.3",
    "react-tooltip": "^4.2.21",
    "remark-gfm": "^1.0.0",
    "slick-carousel": "^1.8.1",
    "typescript": "^4.3.2"
  },

很难猜测发生了什么,正如您指出的那样,它似乎与缓存问题有关,但是,您已经尝试了所有与缓存相关的方法。我建议:

  • 删除 gatsby-plugin-offline 并添加 gatsby-plugin-remove-serviceworker 因为您将不再使用 service-workers

  • 检查输入路径。应该是:

    import { useStaticQuery } from 'gatsby';
    
  • 检查 SEO 组件命名和导入(即:Seo.jsSEO.js)。这同样适用于 Layout