-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tutorial part 4 - cannot read site of undefined #2270
Comments
Hey! Thanks for reporting this issue! Sorry you ran into trouble with the tutorial. Could you try modifying your render function in the layout component to look like: export default ({ children, data }) => {
console.log(data)
return (
<g.Div
margin={`0 auto`}
maxWidth={700}
padding={rhythm(2)}
paddingTop={rhythm(1.5)}
>
<Link to={`/`}>
<g.H3 marginBottom={rhythm(2)} display={`inline-block`}>
{data.site.siteMetadata.title}
</g.H3>
</Link>
<Link className={linkStyle} to={`/about/`}>
About
</Link>
{children()}
</g.Div>
) |
Then look in your console to see what's logged out. If that doesn't work, try restarting your development server. |
Looks like there's a JS error now in your component. Would you mind just starting over? It does look like something went wrong while you were copying files over. If the same error happens again, I'll check it out later to see if a bug has popped up in Gatsby recently. |
I have the similar problem as well. GraphQL Error Unknown field Looks like the schema is not updated (grphiql don't show the new data after restart) Any suggestions how get around it? Thanks |
Same problem here, even after copying and pasting the code straight from the tutorial and restarting the server. |
I've figured it out! Well, for myself at least. The tutorials don't always specify where a gatsby-config.js should go. In tutorial 3, I had the config file in my 'src' file without issues, but after talking with KyleAMatthews I realized that it should actually be created in the root folder, not in src. After moving it to the root directory the error went away! So for Tutorial 4, gatsby-config.js must be in the root directory. Hope this helps someone else! |
Confirmed resolved! |
I've come across a related problem, opened new issue here: #2674 |
Having the same issue - data is undefined (verified by logging as above).
|
I had the same issue: |
Did anyone ever find a solution to this? I am getting this as well having tried everything suggested but don't see a solution suggested. |
@SilasOtoko solution solved the issue for me the tl;dr is move the gatsby-config.js file to the root directory. |
For me the problem is that we should give a name to the query. From export const query = graphql`
query {
site {
siteMetadata {
title
}
}
}
` To export const query = graphql`
query SiteQuery{
site {
siteMetadata {
title
}
}
}
` For me there is a problem with the source code from the tutorial. |
it is not working |
Make sure you are under a page component because graphql works for page components and useStaticQuery works better in non-page components, that can be causing the error.
|
After following steps from "Now let’s start querying" to "It worked!!" - it didn't work :/
https://imgur.com/a/B1Lqw
I get the fail and die error with a red bg as pasted below:
TypeError: Cannot read property 'site' of undefined
new
webpack:///src/layouts/index.js:19
http://localhost:8000/commons.js:39277:25
instantiate
webpack:///
/react-proxy/modules/createClassProxy.js:103/react-dom/lib/ReactCompositeComponent.js:73_default (http://localhost:8000/commons.js:39292:23),
http://localhost:8000/commons.js:27122:17
measureLifeCyclePerf
webpack:///
ReactCompositeComponentWrapper._constructComponentWithoutOwner
webpack:///
/react-dom/lib/ReactCompositeComponent.js:302/react-dom/lib/ReactCompositeComponent.js:277ReactCompositeComponentWrapper._constructComponent
webpack:///
ReactCompositeComponentWrapper.mountComponent
webpack:///
/react-dom/lib/ReactCompositeComponent.js:185/react-dom/lib/ReactReconciler.js:43Object.mountComponent
webpack:///
The text was updated successfully, but these errors were encountered: