question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve error messages of `createPage` API

See original GitHub issue

While experimenting with gatsby by making a simple portfolio site, I made a mistake of not supplying component property to the object passed to createPage function 🙈 This is what I made my code looked like:

const path = require('path')

exports.createPages = ({ boundActionCreators, graphql }) => {
  const { createPage } = boundActionCreators
  const blogPostTemplate = path.resolve('src/templates/blogPost.js')

  return graphql(`
    {
      allMarkdownRemark {
        edges {
          node {
            html
            frontmatter {
              title
              date
              path
              excerpt
            }
          }
        }
      }
    }
  `).then(result => {
      if (result.errors) {
        return Promise.reject(result.errors)
      }

      const { edges: posts } = result.data.allMarkdownRemark
      posts.forEach(({ node: post }) => {
        const { path } = post.frontmatter
        createPage({
          path,
          template: blogPostTemplate  // should be `component: blogPostTemplate`
        })
      })
  })
}

At that time, I didn’t realize the error and was struggling to understand what was going on. The error message I got during the build process looked like:

TypeError: Path must be a string. Received undefined

The above error message is useful but it does not clearly highlight what I was missing.

To maintainers:

What do you think about throwing an error message which reads along the lines of:

Missing required property `component`: Looks like you haven't passed a `component` property to `createPage` function.

We could point the user to the line number of the createPage function invocation.

Note: The above request is not a priority and an enhancement. I’ll let you guys decide if it is worth working on it.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
GregBorrellycommented, Jan 30, 2018

@calcsam Status update: working on the issue, I got stuck migrating an app at work so that took a while.

1reaction
calcsamcommented, Jan 26, 2018

@GregBorrelly it’s yours – i’ll add you to the core team (check your email in the morning) and assign it to you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Misleading error in gatsby-node for `createPage` (`component ...
When using the boundActionCreators's createPage of the createPages API, I get the following error when I don't have a component property: ...
Read more >
Gatsby Node APIs
Documentation on Node APIs used in Gatsby build process for common uses like creating pages.
Read more >
Refrence error in gatsbyjs createPage object - Stack Overflow
I keep getting this error when I try to create a blog page using the createPage code from the Gatsby node API documentation....
Read more >
How to write API errors that keep your users moving forward
The best error messages feel more like guardrails, gently guiding the developer back onto the path and keeping things moving forward. This guide ......
Read more >
Gatsby run build - error at createPages that is working ok on ...
PLEASE help us help you by writing a good post! Hi, my site name is : sleepy-rosalind-fabd9f I'm having errors at building stage...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found