I'm using gatsby to build a very large site (5k+ pages, 300k+ images). The source data is unreliable (e.g. fields are often missing), which leads to errors during the createPage
process.
The issue is that if one single createPage
run throws an error, the entire build fails. So sometimes 5k pages build successfully, then the whole thing crashes because of one error.
I tried wrapping the page creation in a try...catch
but it made no difference:
try {
createPage({
path: node.slug,
component: path.resolve(`./src/templates/BlogPost.js`),
context: {
id: node.id,
},
});
} catch (error) {
console.log(error);
}
(I also tried checking the data at the component level and returning null
if it's not complete, but createPage
still creates a (blank) page, and I don't want that: I just want the page to be skipped if the data is bad)
So my question is: how can one handle errors / failed page creation during the build process so that failed pages are just skipped instead of crashing the whole build?
NB this is almost a duplicate of this question, but the solution there doesn't work for me: I can't render an error page in case of bad data, I need the page to be skipped entirely if this is at all possible