Gatsby: [v2] gatsby-node: Cannot read property "edges" of null in buliding process.

Created on 26 Dec 2018  路  2Comments  路  Source: gatsbyjs/gatsby

Description

I make my site with gatsbyV2 and gatsby-transformer-csv.
gatsby develop is Running without error.
But, when gatsby build error occurs.

https://github.com/aocory/gatsby

Steps to reproduce

When running 'gatsby build' error occurs.

But, when gatsby developerror not occur.

Expected result

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

  15 |       <div className="grid">
  16 |       {
> 17 |         data.allItemCsv.edges.map(({node}) => (
     |                         ^
  18 |           <article key = {node.id}>
  19 |           <image src={logo} alt="Placeholder image"></image>
  20 |           <div class="text">

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

  - cat.js:17 ./src/templates/cat.js.__webpack_exports__.default
    lib/src/templates/cat.js:17:25

  - bootstrap:25 a.render
    lib/webpack/bootstrap:25:1

  - bootstrap:24 a.read
    lib/webpack/bootstrap:24:1

  - bootstrap:36 renderToString
    lib/webpack/bootstrap:36:1

  - gatsby-ssr.js:21 Object.replaceRenderer
    [lib]/[gatsby-plugin-emotion]/gatsby-ssr.js:21:1

  - api-runner-ssr.js:40
    lib/.cache/api-runner-ssr.js:40:39


  - api-runner-ssr.js:36 ./.cache/api-runner-ssr.js.module.exports
    lib/.cache/api-runner-ssr.js:36:25

  - static-entry.js:174 Module../.cache/static-entry.js.__webpack_exports__.default
    lib/.cache/static-entry.js:174:3

  - bootstrap:24 Promise
    lib/webpack/bootstrap:24:1

  - bootstrap:68 new Promise
    lib/webpack/bootstrap:68:1

I tried , but failed things

Environment

Gatsby Version 2.4.7
Windows 10

question or discussion

Most helpful comment

@sidharthachatterjee
I corrected according to your advice and it went well.
I was saved because I was really in trouble. Thank you

All 2 comments

@aocory This breaks when trying to create a page at /category/espresso because in the cat.js template file, the query

query($slug: String!) {
    catCsv(slug: { eq: $slug }) {
      name
      slug
      comment
    }
    allItemCsv(filter: { cat: { eq: $slug } }) {
      edges {
        node {
          name
          slug
          desc
          cat
        }
      }
    }
  }

returns allItemCsv as null

This is because the filter: { cat: { eq: $slug } } doesn't match any lines in item.csv鈥攖here is no item with cat set to espresso

You can fix this by checking for data.allItemCsv.edges before mapping through it in the React component.

With respect to why it runs in development,

  • running gatsby develop, gatsby renders pages as required and therefore the command runs fine (still breaks if you go to /category/espresso)
  • running gatsby build, gatsby renders all pages to create the build and therefore the command fails

@sidharthachatterjee
I corrected according to your advice and it went well.
I was saved because I was really in trouble. Thank you

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ferMartz picture ferMartz  路  3Comments

rossPatton picture rossPatton  路  3Comments

jimfilippou picture jimfilippou  路  3Comments

dustinhorton picture dustinhorton  路  3Comments

kalinchernev picture kalinchernev  路  3Comments