我收到有关此问题的错误报告:https://github.com/gatsbyjs/gatsby/issues/25920 但是盖茨比的人似乎太忙了,所以也许这里的其他人知道这个问题。
请记住,我根本没有在我的代码中使用
StaticQuery
组件。
我遇到了同样的问题。
在拥有它之前我注意到了其他一些开发者:https://github.com/gatsbyjs/gatsby/issues/6350
我看到一些开发者建议从
export
变量中删除 query
,所以这个:
const query = graphql`...`
而不是这个:
export const query = graphql`...`
但这不是我的情况。直到几个小时前一切都很好。
我所有的页面都有这样的查询:
// this is my component
const CollectionProduct = ({ data }) => {...}
// and outside the component is the query
export const query = graphql`
query($handle: String!) {
shopifyCollection(handle: { eq: $handle }) {
products {
id
title
handle
createdAt
}
}
}
}
`
在我在
export
上使用const query
的那个组件中,我所有的页面都是以相同的方式定义的,并且在没有问题之前。我已经升级和降级了 Gatsby 的版本,但还是同样的问题。
我的问题恰好在我向项目添加
.eslintrc.js
配置文件之后出现;由于 ESLint,这是我的项目构建在实时站点上失败的选项吗?
在本地有效,我可以构建项目并在我的
localhost
上看到它,没有任何问题。但是当我看到实时站点时,它会抛出 Loading(StaticQuery)
白屏。而且我什至没有在任何地方使用StaticQuery
组件。只有非页面或模板组件上的 useStaticQuery
钩子。
这是我的 ESLint 配置:
module.exports = {
globals: {
__PATH_PREFIX__: true,
},
'parser': 'babel-eslint',
parserOptions: {
extraFileExtensions: ['.js'],
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
useJSXTextNode: true,
include: ['**/*js'],
},
env: {
es6: true,
node: true,
jest: true,
browser: true,
commonjs: true,
serviceworker: true,
},
extends: ['eslint:recommended', 'plugin:react/recommended', 'semistandard', 'plugin:import/react'],
plugins: ['react'],
rules: {
semi: 'off',
'strict': 0,
curly: [1, 'all'],
'no-console': 'error',
"react/prop-types": 0,
camelcase: ['off', {}],
'react/jsx-uses-vars': 1,
'react/jsx-uses-react': 1,
'react/jsx-boolean-value': 2,
"react/display-name": 'warn',
'react/react-in-jsx-scope': 1,
'brace-style': ['error', '1tbs'],
'comma-dangle': ['error', 'never'],
'linebreak-style': ['error', 'unix'],
'react-hooks/exhaustive-deps': 'off',
'standard/no-callback-literal': [0, []],
'padding-line-between-statements': [
'error',
{ blankLine: 'always', prev: '*', next: 'return' },
{ blankLine: 'always', prev: '*', next: 'multiline-const' },
{ blankLine: 'always', prev: 'multiline-const', next: '*' },
{ blankLine: 'always', prev: '*', next: 'block-like' },
{ blankLine: 'always', prev: 'block-like', next: '*' },
],
'react/jsx-curly-brace-presence': [
'error',
{ props: 'never', children: 'never' },
],
},
};
有什么想法吗?
从浏览器中删除缓存存储并重新加载页面。或硬重新加载页面并查看,这为我解决了问题。
我有一个类似的问题突然发生了。 https://github.com/gatsbyjs/gatsby/issues/24890 上有人建议尝试清理您的项目。
对我来说删除
node_modules
和yarn.lock
然后重新生成它们就成功了!
用
npm i -g gatsby-cli
更新cli为我解决了这个问题
只需删除 yarn.lock 即可完成
以上解决方案都不适合我。
对我有用的一个可能的解决方案是复制并删除显示白屏的页面,生成一个新的构建,然后为下一个构建再次添加相同的页面。这似乎为我解决了这个问题。
目前尚不清楚此解决方法为何有效,但可能是 Gatsby 或其插件存在一些缓存问题导致了该问题。希望这个解决方案也对您有用。