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.

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
- Catch and exit if someone mistakenly puts their gatsby-config.js in the src directory fixes #2674 — committed to gatsbyjs/gatsby by KyleAMathews 6 years ago
- [v2] Merge in master (#4114) * Revert "Update gatsby-browser.js (#3694)" This reverts commit 644d081af58a19aabcff04fcdc98c22e2cf2afb6. * Add 'page.layout' param to 'createPage' docs (#3717) ... — committed to gatsbyjs/gatsby by KyleAMathews 6 years ago
- [v2] Merge in master (#4114) * Revert "Update gatsby-browser.js (#3694)" This reverts commit 644d081af58a19aabcff04fcdc98c22e2cf2afb6. * Add 'page.layout' param to 'createPage' docs (#3717) ... — committed to mwfrost/gatsby by KyleAMathews 6 years ago
Perhaps you didn’t restart
gatsby developafter addinggatsby-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.jsand notgatsby-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.jsthat 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!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.jsimport graphql from 'graphql'But, weirdly, if I then remove that line, it still works…