Gatsby: Gatsby Build Doesn't Work Without Cache

Created on 29 Aug 2017  ยท  5Comments  ยท  Source: gatsbyjs/gatsby

Here is the source for my work-in-progress site: https://github.com/knpwrs/knpw.rs

When I run gatsby build, I get the following output:

โฏ npm run build

> knpw.rs@ build /Users/knpwrs/Workspace/github.com/knpwrs/knpw.rs
> gatsby build

success delete html files from previous builds โ€” 0.005 s
success open and validate gatsby-config.js โ€” 0.004 s
success copy gatsby files โ€” 0.019 s
success source and transform nodes โ€” 0.094 s
success building schema โ€” 0.283 s
success createLayouts โ€” 0.007 s
error Plugin default-site-plugin returned an error


  Error: 

success createPages โ€” 0.024 s
success createPagesStatefully โ€” 0.025 s
GraphQL Error Unknown field `date` on type `frontmatter`

  file: /Users/knpwrs/Workspace/github.com/knpwrs/knpw.rs/src/pages/index.jsx

   1 |
   2 |   query IndexQuery {
   3 |     allMarkdownRemark(
   4 |       sort: { order: DESC, fields: [frontmatter___date] }
   5 |     ) {
   6 |       edges {
   7 |         node {
   8 |           id
   9 |           frontmatter {
  10 |             title
> 11 |             date(formatString: "MMMM DD, YYYY")
     |             ^
  12 |             path
  13 |             tags
  14 |           }
  15 |         }
  16 |       }
  17 |     }
  18 |   }
  19 |

success extract queries from components โ€” 0.155 s
success run graphql queries โ€” 0.002 s
success write out page data โ€” 0.003 s
success update schema โ€” 0.083 s

info bootstrap finished - 1.829 s

success Generating CSS โ€” 4.858 s
success Compiling production bundle.js โ€” 12.092 s

error Generating static HTML for pages failed

When I run gatsby develop I'll get a .cache directory which will then make gatsby build work. If I delete that cache directory then gatsby build goes back to the previous output. Is this intentional? Whats' going on?

Most helpful comment

@markmichon and others check out #1964

Hadn't realized gray-matter was making date objects! Explains this weird bug.

All 5 comments

I ran into something similar and resolved it by ensuring all of my dates in frontmatter were wrapped in quotes. Otherwise I'd have a similar issue where every other build/develop attempt would result in the error you are receiving. It's a temp fix while you're building at the very least.

I wasn't able to narrow down the underlying problem. Perhaps someone with a better understanding of the graphql setup can dig in.

edit: I think I know how to fix this in the way moment is set up. Working on it.

Looks like it is an issue with quotes. I just quoted all of my dates and it works.

Okay, so I narrowed this down further. It's not moment's fault, but rather graymatter's by way of the remark transformer. Graymatter parses a (non-string)date in YAML as a Date object, which seems to make the whole chain mad.

Going to test a fix(albeit an pretty inelegant one involving stringifying and parsing the json) on a few blogs from the readme.

If anyone knows a good reason why stripping the YAML data down to plain objects instead of instanced objects would be a bad idea for this, please let me know. If all goes smoothly I'll put a PR together.

@markmichon and others check out #1964

Hadn't realized gray-matter was making date objects! Explains this weird bug.

I got this same error, when I used the fragment GatsbyContentfulResolutions_noBase64 in a query from the gatsby-node.js. I then replaced the fragment with the query fields and the error went away.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jimfilippou picture jimfilippou  ยท  3Comments

Oppenheimer1 picture Oppenheimer1  ยท  3Comments

mikestopcontinues picture mikestopcontinues  ยท  3Comments

theduke picture theduke  ยท  3Comments

totsteps picture totsteps  ยท  3Comments