Skip to content

Using gatsby-plugin-image causes error: can't access property "image" #34164

Answered by violy
Isaac-Tait asked this question in Help
Discussion options

You must be logged in to vote

You probably missed one thing in your code.
You try to source an image in a bad scope on a undefined object.

You should source your images in the post loop — in map() function scope

data.allMdx.nodes.map((node) => (

something like this :

// ...
{
data.allMdx.nodes.map((node, key) => {
  const {frontmatter} = node
  const image = getImage(frontmatter.image) 
  return (
  <div className="flex justify-center align-middle" key={key}> 
  {/* ... */}
      <GatsbyImage image={image} alt={frontmatter.imageAlt} />
  {/* ... */}
  </div>
  )}
}

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by Isaac-Tait
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants