Gatsby: WebpackError: TypeError: Cannot read property 'frontmatter' of null

Created on 20 Oct 2018  Â·  6Comments  Â·  Source: gatsbyjs/gatsby

Description

Cannot build a working webpage using markdown. With npm develop is ok

Steps to reproduce

Create gatsby page with gatsby new my-page https://github.com/gatsbyjs/gatsby-starter-default

and follow the tutorial: https://www.gatsbyjs.org/docs/adding-markdown-pages/

npm run build

Expected result

Build successfully

Actual result

success Building production JavaScript and CSS bundles — 3.348 s
{ allMarkdownRemark: { edges: [ [Object], [Object], [Object] ] } }

error Building static HTML for pages failed

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

  18 |   return (
  19 |     <Layout>
> 20 |       <Helmet title={`${post.frontmatter.title}`}/>
     |                                             ^
  21 |       <div className="back-top-container sticky-top">
  22 |         <Link to={'/'}>


  WebpackError: TypeError: Cannot read property 'frontmatter' of null

Project: https://github.com/jpomykala/gatsby-issue

Environment

  System:
    OS: macOS 10.14
    CPU: x64 Intel(R) Core(TM) i7-8559U CPU @ 2.70GHz
    Shell: 5.3 - /bin/zsh
  Binaries:
    Node: 8.12.0 - /usr/local/opt/node@8/bin/node
    Yarn: 1.10.1 - /usr/local/bin/yarn
    npm: 6.4.1 - /usr/local/opt/node@8/bin/npm
  Browsers:
    Chrome: 69.0.3497.100
    Firefox: 62.0.3
    Safari: 12.0
  npmPackages:
    gatsby: ^2.0.19 => 2.0.26 
    gatsby-image: ^2.0.15 => 2.0.15 
    gatsby-plugin-catch-links: ^2.0.5 => 2.0.5 
    gatsby-plugin-manifest: ^2.0.5 => 2.0.5 
    gatsby-plugin-offline: ^2.0.5 => 2.0.7 
    gatsby-plugin-react-helmet: ^3.0.0 => 3.0.0 
    gatsby-plugin-sass: ^2.0.1 => 2.0.1 
    gatsby-plugin-sharp: ^2.0.7 => 2.0.7 
    gatsby-remark-copy-images: ^0.2.1 => 0.2.1 
    gatsby-remark-copy-linked-files: ^2.0.5 => 2.0.5 
    gatsby-remark-images: ^2.0.4 => 2.0.4 
    gatsby-remark-prismjs: ^3.0.2 => 3.0.2 
    gatsby-source-filesystem: ^2.0.5 => 2.0.5 
    gatsby-transformer-remark: ^2.1.8 => 2.1.8 
    gatsby-transformer-sharp: ^2.1.4 => 2.1.4 
  npmGlobalPackages:
    gatsby-cli: 2.4.3

Most helpful comment

You need to put the post-page.js file into the folder „templates“ - the tutorial mentions that. The reason behind that is that every js file in the pages folder gets processed to a page and it won’t have access to the context

All 6 comments

You need to put the post-page.js file into the folder „templates“ - the tutorial mentions that. The reason behind that is that every js file in the pages folder gets processed to a page and it won’t have access to the context

Weird, I was thinking that if I set my own path to template it will still work. I think it's worth mention that in tutorial.

Thanks for this - this was my issue! I thought I could create my own folders but I guess you have to keep things separate!

You need to put the post-page.js file into the folder „templates“ - the tutorial mentions that. The reason behind that is that every js file in the pages folder gets processed to a page and it won’t have access to the context

This is not the solution. I have template in folder "templates" and frontmatter is still not detected. Rebuilt site twice and no effect.

@Behinder could you make a reproduction with your code and packages you're using, following these steps so that it can be better looked at? I'm more than happy to take a look at it.

Nah, it's too much effort. I'll stop the project and wait if bug goes away
in 2.1

On Tue, Feb 11, 2020 at 5:22 PM jonniebigodes notifications@github.com
wrote:

@Behinder https://github.com/Behinder could you make a reproduction
with your code and packages you're using, following these steps
https://www.gatsbyjs.org/contributing/how-to-make-a-reproducible-test-case/
so that it can be better looked at? I'm more than happy to take a look at
it.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/gatsbyjs/gatsby/issues/9267?email_source=notifications&email_token=AAEQPFT7WLX7WQ6QH5AIQ53RCLGCXA5CNFSM4F6HN7P2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELNBSHQ#issuecomment-584718622,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAEQPFRQPMPHB3JQD3GS6VTRCLGCXANCNFSM4F6HN7PQ
.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  Â·  3Comments

3CordGuy picture 3CordGuy  Â·  3Comments

rossPatton picture rossPatton  Â·  3Comments

KyleAMathews picture KyleAMathews  Â·  3Comments

timbrandin picture timbrandin  Â·  3Comments