Cannot query field "frontmatter" on type "MarkdownRemark" in gatsby starter blog

Viewed 2249

I was setting up a gatsby-blog and made changes in siteMetadata inside gatsby-config.js.

  siteMetadata: {
    title: `my blog`,
    description: `A Blog starter`,
    author: `dan`,
    authorTagline: 'Learning',
    social: {
      twitter: `asdfg`,
    },

I also deleted everything inside the content folder so that I could add my own blog posts. As of now, content is an empty folder.

Now, on gatsby develop, I'm getting errors. I'm not proficient in gatsby and graphql, and want to set up this blog quickly. Here's the entire error list:

myPC@myPC:~/Downloads/gatsby-blog$ gatsby develop
success open and validate gatsby-configs - 0.046s
success load plugins - 1.021s
warn The Google Analytics plugin requires a tracking ID. Did you mean to add it?
success onPreInit - 0.026s
info One or more of your plugins have changed since the last time you ran Gatsby. As
a precaution, we're deleting your site's cache to ensure there's no stale data.
success initialize cache - 0.022s
success copy gatsby files - 0.037s
success onPreBootstrap - 0.020s
success createSchemaCustomization - 0.069s
success source and transform nodes - 0.131s
success building schema - 0.375s

 ERROR #85901  GRAPHQL

There was an error in your GraphQL query:

Expected type MarkdownRemarkFieldsEnum, found frontmatter___date.

File: gatsby-node.js:7:10


 ERROR #85923  GRAPHQL

There was an error in your GraphQL query:

Cannot query field "fields" on type "MarkdownRemark".

If you don't expect "fields" to exist on the type "MarkdownRemark" it is most likely a typo.
However, if you expect "fields" to exist there are a couple of solutions to common problems:

- If you added a new data source and/or changed something inside gatsby-node.js/gatsby-config.js, please try a restart of your development server
- The field might be accessible in another subfield, please try your query in GraphiQL and use the GraphiQL explorer to see which fields you can query and what shape they have
- You want to optionally use your field "fields" and right now it is not used anywhere. Therefore Gatsby can't infer the type and add it to the GraphQL schema. A quick fix is to add a least one entry with that field ("dummy content")

It is recommended to explicitly type your GraphQL schema if you want to use optional fields. This way you don't have to add the mentioned "dummy content". Visit our docs to learn how you can define the schema for "MarkdownRemark":
https://www.gatsbyjs.org/docs/schema-customization/#creating-type-definitions

File: gatsby-node.js:7:10


 ERROR #85923  GRAPHQL

There was an error in your GraphQL query:

Cannot query field "frontmatter" on type "MarkdownRemark".

If you don't expect "frontmatter" to exist on the type "MarkdownRemark" it is most likely a typo.
However, if you expect "frontmatter" to exist there are a couple of solutions to common problems:

- If you added a new data source and/or changed something inside gatsby-node.js/gatsby-config.js, please try a restart of your development server
- The field might be accessible in another subfield, please try your query in GraphiQL and use the GraphiQL explorer to see which fields you can query and what shape they have
- You want to optionally use your field "frontmatter" and right now it is not used anywhere. Therefore Gatsby can't infer the type and add it to the GraphQL schema. A quick fix is to add a least one entry with that field ("dummy content")

It is recommended to explicitly type your GraphQL schema if you want to use optional fields. This way you don't have to add the mentioned "dummy content". Visit our docs to learn how you can define the schema for "MarkdownRemark":
https://www.gatsbyjs.org/docs/schema-customization/#creating-type-definitions

File: gatsby-node.js:7:10

[
  GraphQLError: Expected type MarkdownRemarkFieldsEnum, found frontmatter___date.
      at Object.EnumValue (/home/myPC/Downloads/gatsby-blog/node_modules/graphql/validation/rules/ValuesOfCorrectType.js:112:29)
      at Object.enter (/home/myPC/Downloads/gatsby-blog/node_modules/graphql/language/visitor.js:324:29)
      at Object.enter (/home/myPC/Downloads/gatsby-blog/node_modules/graphql/language/visitor.js:375:25)
      at visit (/home/myPC/Downloads/gatsby-blog/node_modules/graphql/language/visitor.js:242:26)
      at validate (/home/myPC/Downloads/gatsby-blog/node_modules/graphql/validation/validate.js:73:24)
      at GraphQLRunner.validate (/home/myPC/Downloads/gatsby-blog/node_modules/gatsby/dist/query/graphql-runner.js:84:44)
      at GraphQLRunner.query (/home/myPC/Downloads/gatsby-blog/node_modules/gatsby/dist/query/graphql-runner.js:149:25)
      at /home/myPC/Downloads/gatsby-blog/node_modules/gatsby/dist/bootstrap/create-graphql-runner.js:33:37
      at /home/myPC/Downloads/gatsby-blog/gatsby-node.js:10:7
      at new Promise (<anonymous>)
      at Object.exports.createPages (/home/myPC/Downloads/gatsby-blog/gatsby-node.js:7:10)
      at runAPI (/home/myPC/Downloads/gatsby-blog/node_modules/gatsby/dist/utils/api-runner-node.js:256:37)
      at Promise.catch.decorateEvent.pluginName (/home/myPC/Downloads/gatsby-blog/node_modules/gatsby/dist/utils/api-runner-node.js:375:15)
      at Promise._execute (/home/myPC/Downloads/gatsby-blog/node_modules/bluebird/js/release/debuggability.js:384:9)
      at Promise._resolveFromExecutor (/home/myPC/Downloads/gatsby-blog/node_modules/bluebird/js/release/promise.js:518:18)
      at new Promise (/home/myPC/Downloads/gatsby-blog/node_modules/bluebird/js/release/promise.js:103:10) {
    locations: [ [Object] ]
  },
  GraphQLError: Cannot query field "fields" on type "MarkdownRemark".
      at Object.Field (/home/myPC/Downloads/gatsby-blog/node_modules/graphql/validation/rules/FieldsOnCorrectType.js:53:31)
      at Object.enter (/home/myPC/Downloads/gatsby-blog/node_modules/graphql/language/visitor.js:324:29)
      at Object.enter (/home/myPC/Downloads/gatsby-blog/node_modules/graphql/language/visitor.js:375:25)
      at visit (/home/myPC/Downloads/gatsby-blog/node_modules/graphql/language/visitor.js:242:26)
      at validate (/home/myPC/Downloads/gatsby-blog/node_modules/graphql/validation/validate.js:73:24)
      at GraphQLRunner.validate (/home/myPC/Downloads/gatsby-blog/node_modules/gatsby/dist/query/graphql-runner.js:84:44)
      at GraphQLRunner.query (/home/myPC/Downloads/gatsby-blog/node_modules/gatsby/dist/query/graphql-runner.js:149:25)
      at /home/myPC/Downloads/gatsby-blog/node_modules/gatsby/dist/bootstrap/create-graphql-runner.js:33:37
      at /home/myPC/Downloads/gatsby-blog/gatsby-node.js:10:7
      at new Promise (<anonymous>)
      at Object.exports.createPages (/home/myPC/Downloads/gatsby-blog/gatsby-node.js:7:10)
      at runAPI (/home/myPC/Downloads/gatsby-blog/node_modules/gatsby/dist/utils/api-runner-node.js:256:37)
      at Promise.catch.decorateEvent.pluginName (/home/myPC/Downloads/gatsby-blog/node_modules/gatsby/dist/utils/api-runner-node.js:375:15)
      at Promise._execute (/home/myPC/Downloads/gatsby-blog/node_modules/bluebird/js/release/debuggability.js:384:9)
      at Promise._resolveFromExecutor (/home/myPC/Downloads/gatsby-blog/node_modules/bluebird/js/release/promise.js:518:18)
      at new Promise (/home/myPC/Downloads/gatsby-blog/node_modules/bluebird/js/release/promise.js:103:10) {
    locations: [ [Object] ]
  },
  GraphQLError: Cannot query field "frontmatter" on type "MarkdownRemark".
      at Object.Field (/home/myPC/Downloads/gatsby-blog/node_modules/graphql/validation/rules/FieldsOnCorrectType.js:53:31)
      at Object.enter (/home/myPC/Downloads/gatsby-blog/node_modules/graphql/language/visitor.js:324:29)
      at Object.enter (/home/myPC/Downloads/gatsby-blog/node_modules/graphql/language/visitor.js:375:25)
      at visit (/home/myPC/Downloads/gatsby-blog/node_modules/graphql/language/visitor.js:242:26)
      at validate (/home/myPC/Downloads/gatsby-blog/node_modules/graphql/validation/validate.js:73:24)
      at GraphQLRunner.validate (/home/myPC/Downloads/gatsby-blog/node_modules/gatsby/dist/query/graphql-runner.js:84:44)
      at GraphQLRunner.query (/home/myPC/Downloads/gatsby-blog/node_modules/gatsby/dist/query/graphql-runner.js:149:25)
      at /home/myPC/Downloads/gatsby-blog/node_modules/gatsby/dist/bootstrap/create-graphql-runner.js:33:37
      at /home/myPC/Downloads/gatsby-blog/gatsby-node.js:10:7
      at new Promise (<anonymous>)
      at Object.exports.createPages (/home/myPC/Downloads/gatsby-blog/gatsby-node.js:7:10)
      at runAPI (/home/myPC/Downloads/gatsby-blog/node_modules/gatsby/dist/utils/api-runner-node.js:256:37)
      at Promise.catch.decorateEvent.pluginName (/home/myPC/Downloads/gatsby-blog/node_modules/gatsby/dist/utils/api-runner-node.js:375:15)
      at Promise._execute (/home/myPC/Downloads/gatsby-blog/node_modules/bluebird/js/release/debuggability.js:384:9)
      at Promise._resolveFromExecutor (/home/myPC/Downloads/gatsby-blog/node_modules/bluebird/js/release/promise.js:518:18)
      at new Promise (/home/myPC/Downloads/gatsby-blog/node_modules/bluebird/js/release/promise.js:103:10) {
    locations: [ [Object] ]
  }
]

 ERROR #11321  PLUGIN

"gatsby-node.js" threw an error while running the createPages lifecycle:

Cannot read property 'allMarkdownRemark' of undefined

  35 | 
  36 |         // Create blog posts pages.
> 37 |         const posts = result.data.allMarkdownRemark.edges;
     |                                   ^
  38 | 
  39 |         posts.forEach((post, index) => {
  40 |           const previous =

File: gatsby-node.js:37:35



  TypeError: Cannot read property 'allMarkdownRemark' of undefined
  
  - gatsby-node.js:37 
    /home/myPC/Downloads/gatsby-blog/gatsby-node.js:37:35
  
  - From previous event:
  
  - api-runner-node.js:258 runAPI
    [gatsby-blog]/[gatsby]/dist/utils/api-runner-node.js:258:22
  
  - api-runner-node.js:375 Promise.catch.decorateEvent.pluginName
    [gatsby-blog]/[gatsby]/dist/utils/api-runner-node.js:375:15
  
  - From previous event:
  
  - api-runner-node.js:374 
    [gatsby-blog]/[gatsby]/dist/utils/api-runner-node.js:374:12
  
  - timers.js:456 processImmediate
    internal/timers.js:456:21
  
  - From previous event:
  
  - api-runner-node.js:368 
    [gatsby-blog]/[gatsby]/dist/utils/api-runner-node.js:368:11
  
  - From previous event:
  
  - api-runner-node.js:275 module.exports
    [gatsby-blog]/[gatsby]/dist/utils/api-runner-node.js:275:12
  
  - index.js:421 module.exports
    [gatsby-blog]/[gatsby]/dist/bootstrap/index.js:421:9
  
  - develop-process.js:433 async module.exports
    [gatsby-blog]/[gatsby]/dist/commands/develop-process.js:433:7
  

failed createPages - 0.145s
success createPagesStatefully - 0.094s
success onPreExtractQueries - 0.003s
success update schema - 0.045s

 ERROR #85901  GRAPHQL

There was an error in your GraphQL query:

Expected type MarkdownRemarkFieldsEnum, found frontmatter___date.

File: src/pages/index.js:49:40


 ERROR #85901  GRAPHQL

There was an error in your GraphQL query:

Unknown argument "fields" on field "markdownRemark" of type "Query".

GraphQL request:9:20
 8 |     }
 9 |     markdownRemark(fields: { slug: { eq: $slug } }) {
   |                    ^
10 |       id

File: src/templates/blog-post.js:77:20


 ERROR #85923  GRAPHQL

There was an error in your GraphQL query:

Cannot query field "fields" on type "MarkdownRemark".

If you don't expect "fields" to exist on the type "MarkdownRemark" it is most likely a typo.
However, if you expect "fields" to exist there are a couple of solutions to common problems:

- If you added a new data source and/or changed something inside gatsby-node.js/gatsby-config.js, please try a restart of your development server
- The field might be accessible in another subfield, please try your query in GraphiQL and use the GraphiQL explorer to see which fields you can query and what shape they have
- You want to optionally use your field "fields" and right now it is not used anywhere. Therefore Gatsby can't infer the type and add it to the GraphQL schema. A quick fix is to add a least one entry with that field ("dummy content")

It is recommended to explicitly type your GraphQL schema if you want to use optional fields. This way you don't have to add the mentioned "dummy content". Visit our docs to learn how you can define the schema for "MarkdownRemark":
https://www.gatsbyjs.org/docs/schema-customization/#creating-type-definitions

File: src/templates/blog-post.js:81:7


 ERROR #85923  GRAPHQL

There was an error in your GraphQL query:

Cannot query field "frontmatter" on type "MarkdownRemark".

If you don't expect "frontmatter" to exist on the type "MarkdownRemark" it is most likely a typo.
However, if you expect "frontmatter" to exist there are a couple of solutions to common problems:

- If you added a new data source and/or changed something inside gatsby-node.js/gatsby-config.js, please try a restart of your development server
- The field might be accessible in another subfield, please try your query in GraphiQL and use the GraphiQL explorer to see which fields you can query and what shape they have
- You want to optionally use your field "frontmatter" and right now it is not used anywhere. Therefore Gatsby can't infer the type and add it to the GraphQL schema. A quick fix is to add a least one entry with that field ("dummy content")

It is recommended to explicitly type your GraphQL schema if you want to use optional fields. This way you don't have to add the mentioned "dummy content". Visit our docs to learn how you can define the schema for "MarkdownRemark":
https://www.gatsbyjs.org/docs/schema-customization/#creating-type-definitions

File: src/templates/blog-post.js:86:7

failed extract queries from components - 0.476s
success write out requires - 0.046s
success write out redirect data - 0.013s
success Build manifest and related icons - 0.184s
success onPostBootstrap - 0.202s
⠀
info bootstrap finished - 5.922s
⠀
success run static queries - 0.058s - 3/3 51.39/s
success run page queries - 0.024s - 4/4 167.48/s
warn Browserslist: caniuse-lite is outdated. Please run:
npx browserslist@latest --update-db

 ERROR #98123  WEBPACK

Generating development JavaScript bundle failed


/home/myPC/Downloads/gatsby-blog/src/pages/index.js
  49:40  error  Expected type MarkdownRemarkFieldsEnum, found frontmatter___date  graphql/template-strings

✖ 1 problem (1 error, 0 warnings)


File: src/pages/index.js

failed Building development bundle - 4.692s

Help me fix this issue. Thanks!

1 Answers

You are getting errors because you deleted the /content folder, so all references and queries that point to that content, are now breaking the code because can't fetch what you are querying.

You have references to the missing content in your gatsby-node.js and in your blog-post.js.

The solutions:

  • Restore the dummy initial content to avoid the code-breaking queries and replace it as soon as you add your new posts
  • Comment all the queries and references to the query objects (for example in your blog-post.js). This is tedious and not recommended, since you will need to uncomment/restore it as soon as you add new content.

P.S: a query reference to a content may be something like:

    allMarkdownRemark(
      sort: { fields: [frontmatter___date], order: DESC }
      limit: 1000
    ) {
      edges {
        node {
          fields {
            slug
          }
          frontmatter {
            title
          }
        }
      }
    }
  }
`
Related