Gatsby和netlify-npm运行启动时出现cover_image错误



https://medium.com/@d3vma/build-a-blog-portfolio-with-reacts-gatsby-and-netlify-cms-fc1bee6451a5

我按照上面的教程制作了一个Gatsby和Netlify网站,但我在下面的Frontmatter中收到了一条自定义类型的错误消息,谢谢。

ERROR #85923  GRAPHQL
There was an error in your GraphQL query:
Cannot query field "cover_image" on type "Frontmatter".
If you don't expect "cover_image" to exist on the type "Frontmatter" it is most likely a typo.
However, if you expect "cover_image" to exist there are a couple of solutions to common problems:
- If you added a new data source and/or changed something inside gatsby-node.js/gatsby-config.js, please try a restart of your development server
- The field might be accessible in another subfield, please try your query in GraphiQL and use the GraphiQL explorer to see which fields you can query and what  
shape they have
- You want to optionally use your field "cover_image" and right now it is not used anywhere. Therefore Gatsby can't infer the type and add it to the GraphQL     
schema. A quick fix is to add at least one entry with that field ("dummy content")
It is recommended to explicitly type your GraphQL schema if you want to use optional fields. This way you don't have to add the mentioned "dummy content". Visit 
our docs to learn how you can define the schema for "Frontmatter":
https://www.gatsbyjs.com/docs/reference/graphql-data-layer/schema-customization#creating-type-definitions
File: srcpagesindex.js:98:9
failed extract queries from components - 3.793s
success write out requires - 0.105s
success run static queries - 0.051s - 2/2 39.01/s
success run page queries - 0.039s - 2/2 51.62/s
DONE  Compiled successfully in 14427ms                                                                                                                  10:01:51⠀
I  Netlify CMS is running at http://localhost:8000/admin/
ERROR #98123  WEBPACK
Generating development JavaScript bundle failed

C:Usersnosy_DesktopReactgatsmesrcpagesindex.js
98:9  error  Cannot query field "cover_image" on type "Frontmatter"  graphql/template-strings
✖ 1 problem (1 error, 0 warnings)

failed Building development bundle - 28.582s
ERROR in
C:Usersnosy_DesktopReactgatsmesrcpagesindex.js
98:9  error  Cannot query field "cover_image" on type "Frontmatter"  graphql/template-strings
✖ 1 problem (1 error, 0 warnings)

webpack compiled with 1 error

这些是与cover_image相关的其他部分。在Config.yml中,集合下的字段:

{标签:"封面图像",名称:"封面图片",小部件:"图像",必需:false}

在index.js 中

return (
...
<GatsbyImage
image={post.frontmatter.cover_image?.childImageSharp?.gatsbyImageData}
className="h-72 w-full gatsby-bg-image rounded mb-3"
alt={title} />
...)

您的问题缺乏细节、实现和结构,但假设项目是在本地构建的。我会尝试在两种环境(Netlify和本地(中强制使用相同的Node版本。

在项目的根目录中运行:

node -v > .nvmrc

这将创建一个包含本地Node版本的.nvmrc文件。Netlify在部署时将使用该版本来构建项目,从而迫使环境在与本地环境相同的工作版本中工作。

最新更新