I have a very simple Gatsby application. I am running gatsby develop on that and it works fine but when I run gatsby build I am getting an error. I am not sure why the develop would work and the build wouldn't. Not sure what I am missing!
import React from "react"
import Layout from "./layout"
const ProductTemplate = ({ pageContext }) => {
const { product } = pageContext
return (
<Layout>
<h1>{product.title}</h1>
<div>{product.description}</div>
</Layout>
)
}
export default ProductTemplate
This is the exact error
8 | return (
9 | <Layout>
> 10 | <h1>{product.title}</h1>
| ^
11 | <div>{product.description}</div>
12 |
WebpackError: TypeError: Cannot read property 'title' of undefined
- product.js:10
src/pages/product.js:10:20
gatsby-node.js
const path = require(`path`)
exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions
// Query for all products in Shopify
const result = await graphql(`
query {
allShopifyProduct(sort: { fields: [title] }) {
edges {
node {
title
shopifyId
handle
description
availableForSale
priceRange {
maxVariantPrice {
amount
}
minVariantPrice {
amount
}
}
}
}
}
}
`)
// Iterate over all products and create a new page using a template
// The product "handle" is generated automatically by Shopify
result.data.allShopifyProduct.edges.forEach(({ node }) => {
createPage({
path: `/product/${node.handle}`,
component: path.resolve(`./src/pages/product.js`),
context: {
product: node,
},
})
})
}