【发布时间】:2021-12-24 09:59:52
【问题描述】:
概述
我使用的是 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
}
}
}
}
`
)
※由于它在秘密模式下正常工作,我想知道缓存是否有问题。
我尝试了什么
删除盖茨比
$ yarn remove gatsby$ rm -rf node_modules$ yarn install$ gatsby build && gatsby serve
执行 gatsby clean 命令
$ gatsby clean
更改组件名称和文件
https://github.com/gatsbyjs/gatsby/issues/24902#issuecomment-847926225
删除 .cache 文件
我的环境
操作系统:MacOS
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"
},
【问题讨论】:
-
可以提供沙盒吗?
标签: reactjs typescript react-hooks graphql gatsby