In Gatsby I'm trying to create nodes with fetching the json in gatsby-node.js. The issue is that when I'm using fetch I'm getting build errors. When I load the json directly from its path it works. Can anyone put me in the right direction with using fetch instead of directly load the json from path...? Right now I'm having this code with direct path to json:
const path = require("path")
const pages = require("./pages.json")
exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions
const queryResults = pages
const productTemplate = path.resolve(`src/templates/product.js`)
queryResults.forEach(node => {
createPage({
path: `${node.page}`,
component: productTemplate,
context: {
// This time the entire product is passed down as context
product: node,
},
})
})
}