Improve error messages of `createPage` API
See original GitHub issueWhile 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:
- Created 6 years ago
- Comments:7 (7 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@calcsam Status update: working on the issue, I got stuck migrating an app at work so that took a while.
@GregBorrelly it’s yours – i’ll add you to the core team (check your email in the morning) and assign it to you!