微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决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次检查

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。