无法读取未定义的 gatsby graphql 的 属性 '__reactstandin__key'

Cannot read property '__reactstandin__key' of undefined gatsby graphql

我是 gatsby 和 graphql 的新手。 尝试使用 graphql 获取图像,控制台返回图像日期, 但接下来我得到错误:

TypeError: Cannot read property '__reactstandin__key' of undefined

这就是我获取图像的代码:

export const fluidImage = graphql`
  fragment fluidImage on File {
    childImageSharp {
      fluid(maxWidth: 1000) {
        ...GatsbyImageSharpFluid
      }
    }
  }
`

export const pageQuery = graphql`
  query {
    myPhoto: file(relativePath: { eq: "me.png" }) {
      ...fluidImage
    }
  }
`

渲染中

{console.log(this.props.data.myPhoto.childImageSharp.fluid)}
<Img fluid={this.props.data.myPhoto.childImageSharp.fluid} />

我得到了带有 base64 数据的日志。 什么会导致此错误?

我遇到这个错误是因为我使用的是命名导出而不是默认导出。

使用:

import Img from "gatsby-image"

不要使用:

import {Img} from "gatsby-image"