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?
If you don't set a Node version, Gatsby cloud will use the following defaults: The default Node. js version is v14 . If you are using NPM 7, the default is v16.
Gatsby is built using JavaScript, and requires the Node. js runtime. Installing Node. js also installs npm, the Node.
js / gatsby-node. ts is run once in the process of building your site. You can use its APIs to create pages dynamically, add data into GraphQL, or respond to events during the build lifecycle.
Have 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)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With