gatsby: Tutorial Part 4 - Unknown field `siteMetadata` on type `Site`

Followed the tutorial step by step. And I get the following error related to the graph query.

  GraphQL Error Unknown field `siteMetadata` on type `Site`
  file: C:/Code/Projects/bss3/prt4-data/src/layouts/index.js

  1 |
  2 |   query LayoutQuery {
  3 |     site {
> 4 |       siteMetadata {
    |       ^
  5 |         title
  6 |       }
  7 |     }
  8 |   }

As per tutorial, this is defined in gatsby-config.js which is in the root. image

Repeated more than once, starting from scratch. npm: 5.4.2 node: 6.11.3

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 22 (8 by maintainers)

Commits related to this issue

Most upvoted comments

Perhaps you didn’t restart gatsby develop after adding gatsby-config.js? The schema doesn’t get rebuilt until then so any queries to siteMetadata would fail.

@martinpsz I think its too late, but I still want to reply. Maybe someone else find it useful. The point is that you name your file gatsby.config.js and not gatsby-config.js. Have the same issue, and after renaming everything works as expected.

I added this PR https://github.com/gatsbyjs/gatsby/pull/4101 that checks if your gatsby-config.js is in the src directory and politely tells you to move it to the correct place 😃 hopefully that helps people in the future who make this very understandable mistake!

🤕 🌴 In my case it was path to my gatsby-config.js that was wrong, make sure it is in the root and not /src/ dir as it was in my case. You see this error when it’s in the wrong dir, thanks Kyle!

What is the path to your gatsby-config.js? Could you paste it here?

Does the polite warning occur before any other checks? I didn’t notice it and I ran a brand new Gatsby 2.0 and ran into this where I had the config inside src

I resolved this by including the following line in layouts\index.js import graphql from 'graphql'

But, weirdly, if I then remove that line, it still works…