gatsby: gatsby develop ok, but gatsby build failed

Description

gatsby develop ok, but gatsby build failed

Environment

Gatsby version: 1.1.28 Node.js version: 8.9.3 Operating System: Ubuntu 16.04

File contents (if changed):

This is the source: https://github.com/aquabubu/home-gatsby

What happened:

‘gatsby develop’ ok, but ‘gatsby build’ failed.

success delete html files from previous builds — 0.174 s
success open and validate gatsby-config.js — 0.004 s
success copy gatsby files — 0.031 s
success onPreBootstrap — 0.005 s
success source and transform nodes — 0.587 s
success building schema — 0.296 s
success createLayouts — 0.009 s
success createPages — 0.524 s
success createPagesStatefully — 0.026 s
success onPreExtractQueries — 0.001 s
success update schema — 0.186 s
success extract queries from components — 0.109 s
success run graphql queries — 0.186 s
success write out page data — 0.029 s
success write out redirect data — 0.000 s
success onPostBootstrap — 0.000 s

info bootstrap finished - 3.592 s

Warning: Accessing PropTypes via the main React package is deprecated, and will be removed in  React v16.0. Use the latest available v15.* prop-types package from npm instead. For info on usage, compatibility, migration and more, see https://fb.me/prop-types-docs
Warning: Accessing createClass via the main React package is deprecated, and will be removed in React v16.0. Use a plain JavaScript class instead. If you're not yet ready to migrate, create-react-class v15.* is available on npm as a temporary, drop-in replacement. For more info see https://fb.me/react-create-class
 DONE  Compiled successfully in 11757ms                                                                                                                                                                                                                               23:05:07


You can now view aquabubu in the browser.

  http://localhost:8000/

View GraphiQL, an in-browser IDE, to explore your site's data and schema

  http://localhost:8000/___graphql

Note that the development build is not optimized.
To create a production build, use gatsby build

 WAIT  Compiling...                                                                                                                                                                                                                                                   23:05:07

 DONE  Compiled successfully in 445ms

However, gatsby build failed.

success delete html files from previous builds — 0.119 s
success open and validate gatsby-config.js — 0.005 s
success copy gatsby files — 0.020 s
success onPreBootstrap — 0.005 s
success source and transform nodes — 0.553 s
success building schema — 0.283 s
success createLayouts — 0.011 s
success createPages — 0.516 s
success createPagesStatefully — 0.025 s
success onPreExtractQueries — 0.001 s
success update schema — 0.169 s
success extract queries from components — 0.083 s
success run graphql queries — 0.027 s
success write out page data — 0.008 s
success write out redirect data — 0.001 s
success onPostBootstrap — 0.001 s

info bootstrap finished - 3.248 s

success Building CSS — 15.796 s
success Building production JavaScript bundles — 35.495 s
⠂ Building static HTML for pages
error Building static HTML for pages failed

See our docs page on debugging HTML builds for help https://goo.gl/yL9lND

  47 |     const postOverlapClass = mobile ? "post-overlap-mobile" : "post-overlap";
  48 |     const postNode = this.props.data.markdownRemark;
> 49 |     const post = postNode.frontmatter;
     |                           ^
  50 |     if (!post.id) {
  51 |       post.id = slug;
  52 |     }


  WebpackError: Cannot read property 'frontmatter' of undefined
  
  - post.js:49 PostTemplate.render
    src/templates/post.js:49:27
  
  - ReactCompositeComponent.js:796 ReactCompositeComponentWrapper._renderValidatedComponentWithoutOwnerOrContext
    ~/react-dom/lib/ReactCompositeComponent.js:796:1
  
  - ReactCompositeComponent.js:819 ReactCompositeComponentWrapper._renderValidatedComponent
    ~/react-dom/lib/ReactCompositeComponent.js:819:1
  
  - ReactCompositeComponent.js:359 ReactCompositeComponentWrapper.performInitialMount
    ~/react-dom/lib/ReactCompositeComponent.js:359:1
  
  - ReactCompositeComponent.js:255 ReactCompositeComponentWrapper.mountComponent
    ~/react-dom/lib/ReactCompositeComponent.js:255:1
  
  - ReactReconciler.js:43 Object.mountComponent
    ~/react-dom/lib/ReactReconciler.js:43:1
  
  - ReactMultiChild.js:234 ReactDOMComponent.mountChildren
    ~/react-dom/lib/ReactMultiChild.js:234:1
  
  - ReactDOMComponent.js:657 ReactDOMComponent._createContentMarkup
    ~/react-dom/lib/ReactDOMComponent.js:657:1
  
  - ReactDOMComponent.js:524 ReactDOMComponent.mountComponent
    ~/react-dom/lib/ReactDOMComponent.js:524:1
  
  - ReactReconciler.js:43 Object.mountComponent
    ~/react-dom/lib/ReactReconciler.js:43:1

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 22 (4 by maintainers)

Most upvoted comments

On occasion, and I can’t technically explain why, I have deleted the .cache/ and public/ folders and run the build process again and it’s worked as expected.

For any poor soul getting this far without solution: The problem must have been the 404.js file in /pages. The thing is that Gatsby does not render it in dev (instead it shows useful debug page). Make sure you can render that page. What @maidh91 posted seems like complaining about missing frontmatter. Frontmatter is not available in 404.js

I had this same issue the other day. Make sure you don’t have any empty js files. That seems to break the minify on the build and through errors for things that aren’t error.