【问题标题】:Gatsby Cannot read property 'childImageSharp' of null盖茨比无法读取 null 的属性“childImageSharp”
【发布时间】:2021-01-08 18:49:24
【问题描述】:

我正在使用 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 将是一个空白站点

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

提前致谢!

【问题讨论】:

  • 你能发布你的graphql查询吗,或者告诉我源代码中的路径
  • 当然我在这篇文章之后 10 分钟修复了它,但在之前的 8 小时内没有修复它。我的 markdown 文件中确实存在拼写错误,我还添加了一个检查以仅添加 如果屏幕截图frontmatter 不是 null .. 无论如何都是 ty :)

标签: javascript node.js gatsby gatsby-image


【解决方案1】:

在我的代码中添加了{node.frontmatter.screenshot &amp;&amp; &lt;Img... /&gt;},它确实让我构建了它,然后发现我的markdown文件中确实有拼写错误,我没有看到我之前检查过的100次-_-

【讨论】:

    猜你喜欢
    • 2021-04-09
    • 2020-02-03
    • 2020-03-16
    • 2021-02-07
    • 2020-07-18
    • 2023-03-14
    • 2018-12-27
    • 2022-01-21
    • 2020-02-25
    相关资源
    最近更新 更多