最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - getNode() method not found in gatsby-node.js with the latest version of Gatsby - Stack Overflow

programmeradmin2浏览0评论

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?

Share Improve this question edited Dec 20, 2018 at 14:44 Madrus asked Dec 20, 2018 at 14:18 MadrusMadrus 7467 silver badges13 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 19

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)
  }
}
发布评论

评论列表(0)

  1. 暂无评论