I'm creating pages programmatically in gatsby from MD files. the issues I'm having is I'm using the from gatsby-plugin-image to pull the image from the frontmatter of said MD file when the page loads the img is not rendered and i get and error gatsby-plugin-image] Missing image prop
this is the file and graphql set up
import React from "react";
import { graphql } from "gatsby";
import Layout from "../components/Layout";
import {Button, Card, CardBody, CardTitle } from "reactstrap";
import { GatsbyImage, getImage } from "gatsby-plugin-image";
import "../styles/main.scss";
const ProductPage = ({ data }) => {
const post = data.markdownRemark;
const image = getImage(post.image)
return (
<Layout>
<div>
<Card>
<GatsbyImage
className="card-image-top"
src={image}
alt={post.description}
placeholder="blurred"
width={500}
layout="constraint"
/>
<CardTitle>{post.frontmatter.title}</CardTitle>
<CardBody>
<div dangerouslySetInnerHTML={{ __html: post.html }} />
<Button
className="btn btn-outline-secondary float-right" color="light">Buy</Button>
</CardBody>
</Card>
</div>
</Layout>
);
};
export const query = graphql`
query($slug: String!) {
markdownRemark(fields: { slug: { eq: $slug } }) {
html
frontmatter {
title
description
image {
childImageSharp {
gatsbyImageData(
width: 500
placeholder: BLURRED
formats: [AUTO]
)
}
}
}
}
}
`;
export default ProductPage;
I have tried a few different props such as changing
src={post.frontmatter.image} to src={image},
and changing
const image = getImage(post.image) to const image = getImage(post.frontmatter.image)
as you can see the title works fine so it has to be an issue with the image.
also when I use the same query in graphiql it does return the image.
hello there. this is it.
', frontmatter: { title: 'My tattoos dont like you either', description: "well it's true they don't", image: { childImageSharp: [Object] } } } – Brandon.b Mar 11 '21 at 20:42