Gatsby: Unknown argument "formatString" on field "date" of type "MarkdownRemarkFrontmatter".

Created on 19 Sep 2020  Â·  6Comments  Â·  Source: gatsbyjs/gatsby

Referencing: #26893 (and from a few years ago #2096) I tried removing all of my md files, then running gatsby clean and then npm run develop but I am still getting the

Unknown argument "formatString" on field "date" of type "MarkdownRemarkFrontmatter".

I am getting this error on three files:

blog-post.js
graphql query in question:

export const pageQuery = graphql`
  query BlogPostBySlug($slug: String!) {
    site {
      siteMetadata {
        title
      }
    }
    markdownRemark(fields: { slug: { eq: $slug } }) {
      id
      excerpt(pruneLength: 160)
      html
      frontmatter {
        title
        date(formatString: "MMMM DD, YYYY")
        description
      }
    }
  }
`

search.js
graphql query in question:

export const pageQuery = graphql`
    query {
        allMarkdownRemark(sort: { order: DESC, fields: frontmatter___date }) {
            edges {
                node {
                    excerpt
                    id
                    frontmatter {
                        title
                        description
                        date(formatString: "MMMM DD, YYYY")
                    }
                    fields {
                        slug
                    }
                }
            }
        }
    }
`

index.js
graphql query in question:

export const pageQuery = graphql`
  query {
    site {
      siteMetadata {
        title
      }
    }
    allMarkdownRemark(sort: { fields: [frontmatter___date], order: DESC }) {
      edges {
        node {
          excerpt
          fields {
            slug
          }
          frontmatter {
            date(formatString: "MMMM DD, YYYY")
            title
            description
          }
        }
      }
    }
  }
`

Interestingly after deleting all the md files I got a new message:

 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 at 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

A few days ago this bug popped up after a git commit. Everything was working fine then I pushed some mobile header/tailwind adjustments to my repo and this error popped up. My temporary workaround is to delete

(formatString: "MMMM DD, YYYY)

from the query.

bug

Most helpful comment

the type of your frontmatter date field has changed from Date to String. Most likely the reason (at least for me) it is that one of your posts has an invalid date (in my case I had date: 2020-079-20T08:11:45+02:00). Check all your frontmatter dates and ensure that they are valid.

All 6 comments

Failed to compile

There was an error in your GraphQL query:

Unknown argument "formatString" on field "date" of type "MarkdownRemarkFrontmatter".

GraphQL request:14:14
13 |         title
14 |         date(formatString: "MMMM DD, YYYY")
   |              ^
15 |         description

File: /Users/isaactait/Desktop/100_Days_of_Code/gatsby-fallfish-tenkara-blog/src/templates/blog-post.js

./src/templates/blog-post.js
Module Error (from ./node_modules/eslint-loader/index.js):

/Users/isaactait/Desktop/100_Days_of_Code/gatsby-fallfish-tenkara-blog/src/templates/blog-post.js
  67:14  error  Unknown argument "formatString" on field "date" of type "MarkdownRemarkFrontmatter"  graphql/template-strings

✖ 1 problem (1 error, 0 warnings)

Just in case it is helpful:

{
  "name": "gatsby-blog",
  "private": true,
  "description": "Exploring Japan One River At A Time",
  "version": "0.1.0",
  "author": "Isaac Tait <----email---->",
  "bugs": {
    "url": "https://github.com/gatsbyjs/gatsby/issues"
  },
  "dependencies": {
    "gatsby": "^2.24.63",
    "gatsby-image": "^2.4.19",
    "gatsby-plugin-feed": "^2.5.12",
    "gatsby-plugin-manifest": "^2.4.30",
    "gatsby-plugin-netlify": "^2.3.15",
    "gatsby-plugin-offline": "^3.2.28",
    "gatsby-plugin-postcss": "^2.3.12",
    "gatsby-plugin-react-helmet": "^3.3.11",
    "gatsby-plugin-sharp": "^2.6.36",
    "gatsby-plugin-typography": "^2.5.11",
    "gatsby-remark-copy-linked-files": "^2.3.15",
    "gatsby-remark-images": "^3.3.30",
    "gatsby-remark-prismjs": "^3.5.13",
    "gatsby-remark-responsive-iframe": "^2.4.14",
    "gatsby-remark-smartypants": "^2.3.11",
    "gatsby-source-filesystem": "^2.3.30",
    "gatsby-transformer-remark": "^2.8.35",
    "gatsby-transformer-sharp": "^2.5.15",
    "prismjs": "^1.21.0",
    "react": "^16.12.0",
    "react-dom": "^16.12.0",
    "react-helmet": "^5.2.1",
    "react-pro-sidebar": "^0.4.4",
    "react-typography": "^0.16.19",
    "typography": "^0.16.19",
    "typography-theme-wordpress-2016": "^0.16.19"
  },
  "devDependencies": {
    "prettier": "2.1.1",
    "tailwindcss": "^1.8.10"
  },
  "homepage": "https://github.com/gatsbyjs/gatsby-starter-blog#readme",
  "keywords": [
    "gatsby"
  ],
  "license": "0BSD",
  "main": "n/a",
  "repository": {
    "type": "git",
    "url": "git+https://github.com/gatsbyjs/gatsby-starter-blog.git"
  },
  "scripts": {
    "build": "gatsby build",
    "develop": "gatsby develop",
    "format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md}\"",
    "start": "npm run develop",
    "serve": "gatsby serve",
    "clean": "gatsby clean",
    "test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\" && exit 1"
  }
}

the type of your frontmatter date field has changed from Date to String. Most likely the reason (at least for me) it is that one of your posts has an invalid date (in my case I had date: 2020-079-20T08:11:45+02:00). Check all your frontmatter dates and ensure that they are valid.

Thank you @rburgst you were spot on. I had wrapped the date fields in my md files with "", which made it a string... Somehow though my mistake did not throw the error for several commits... Thanks again for your help.

FYI, we are still encountering this issue on all new MD files. We created a new MD file which was an exact copy of another file that didn't throw any errors on the date field. Then when we tried to re-run "gatsby develop" we again got the error: Unknown argument "formatString" on field "date" of type "MarkdownRemarkFrontmatter".

We checked our dates and everything is formatted correctly, and the file is no different (except for the title), than the MD file which works and doesn't throw an error. Wondering if either of you has a clue as to what is causing this sudden error on the data fields? Issac: How did you fix your error? Our original fix doesn't work anymore.

@osseonews Per chance did you try gatsby clean before running gatsby develop? I read that had helped some folks... Fortunately for me I only 16 md files to go through, but 14 of those md files the date field had been wrapped in "" which was causing my error.

I ended up going in and changing all the date fields from this format: date: "April 15, 2015" into this format: date: 2015-04-15T03:13:00+02:00 running gatsby clean and then gatsby develop and the error was gone

Was this page helpful?
0 / 5 - 0 ratings

Related issues

brandonmp picture brandonmp  Â·  3Comments

magicly picture magicly  Â·  3Comments

rossPatton picture rossPatton  Â·  3Comments

3CordGuy picture 3CordGuy  Â·  3Comments

dustinhorton picture dustinhorton  Â·  3Comments