Am working through the official Gatsby tutorial here. Up until step 7 everything worked 100% fine. In step 7 "Programmatically create pages from data", this snippet is listed for gatsby-node.js
(as is, no imports):
exports.onCreateNode = ({ node }) => {
if (node.internal.type === `MarkdownRemark`) {
const fileNode = getNode(node.parent)
console.log(`\n`, fileNode.relativePath)
}
}
However, when running gatsby develop
I get: ReferenceError: getNode is not defined
. I have googled it up for quite some time, and it seems that there may have been some breaking changes recently in the latest versions of Gatsby. Does anyone have an idea what could be the reason for this and how to fix the missing reference? Maybe some module should be imported?
Am working through the official Gatsby tutorial here. Up until step 7 everything worked 100% fine. In step 7 "Programmatically create pages from data", this snippet is listed for gatsby-node.js
(as is, no imports):
exports.onCreateNode = ({ node }) => {
if (node.internal.type === `MarkdownRemark`) {
const fileNode = getNode(node.parent)
console.log(`\n`, fileNode.relativePath)
}
}
However, when running gatsby develop
I get: ReferenceError: getNode is not defined
. I have googled it up for quite some time, and it seems that there may have been some breaking changes recently in the latest versions of Gatsby. Does anyone have an idea what could be the reason for this and how to fix the missing reference? Maybe some module should be imported?
1 Answer
Reset to default 19Have just figured out the answer. It was my own typo. I did not add the second getNode
parameter to the onCreateNode
function:
exports.onCreateNode = ({ node, getNode }) => {
if (node.internal.type === `MarkdownRemark`) {
const fileNode = getNode(node.parent)
console.log(`\n`, fileNode.relativePath)
}
}