Gatsby无法读取null的属性“ childImageSharp”

问题描述

我正在用gatsby构建我的第一个项目,但是找不到解决图像问题的方法

我的代码here

当我尝试运行gatsby build时,出现此错误

Failed Building static HTML for pages - 10.907s

 ERROR #95313

Building static HTML Failed for path "/posts/2"

See our docs page for more info on this error: https://gatsby.dev/debug-html


  27 |                         return (
  28 |                             <div className={blogListStyles.cards}>
> 29 |                                 <Img sizes={node.frontmatter.screenshot.childImageSharp.sizes} />
     |                                                                         ^
  30 |                                 <Link to={`/blog/${node.fields.slug}`}>
  31 |                                 <div className={blogListStyles.title}>{node.frontmatter.title}</div>
  32 |                                 <div className={blogListStyles.subtitle} dangerouslySetInnerHTML={{__html: node.excerpt}}></div>


  Webpackerror: TypeError: Cannot read property 'childImageSharp' of null

  - blog-list-template.js:29
    src/templates/blog-list-template.js:29:73

  - blog-list-template.js:25
    src/templates/blog-list-template.js:25:28

我找到了很多解决方案,但是没有一个我有用,我什至试图设置一个Linux子系统,因为我读到它可以解决问题,但不能解决

我多次检查了.md文件,但找不到任何错字等

当我运行开发模式时,/ posts / 2将是一个空白站点

如果有人可以看一下我的代码,我将不胜感激,在这里我迷路了:(

谢谢!

解决方法

在我的代码中添加了{node.frontmatter.screenshot && <Img... />},这让我得以构建它,然后发现我在markdown文件中确实有错别字,在-_-

之前,我没有看到100次检查