I receive this error when executing: gatsby build
ERROR #85920 GRAPHQL
There was an error in your GraphQL query:
Variable "$slug" of required type "String!" was not provided
query homeyassineContainersmyBlogsrcpagestemplatehealthJs3338664333($slug: String!) {
contentfulBlogHealth(slug: {eq: $slug}) {
title,
date(formatString: "MMMM Do, YYYY"),
body {
json
},
id
}
}
Top comments (7)
Are you sure the slug variable is passed correctly. It seems like this query isnt getting slug variable which is mandatory to run this query
Good evening, and thanks ahead of time for any help.
when run "gatsby develop", I received the all data without these errors, but when use "gatsby build" I received this error "Variable "$slug" of required type "String!" was not provided.".
I found the solution
The issue is you should not put template files in src/pages folder.
It so happens that I have already moved my
single-post.js
,post.js
and otherCPT
.js files into a new, custom folder (/src/templates).If this didn't work then remove ! mark from ($slug: String)
Thank you!
Hello, I'm experiencing the same issue as the author of the post. I found your solution works, but I would like to know why this is happening and why moving the template file to another directory solves the problem.
Thank you!
Don't know brother, It's been awhile since I'm using gatsby.
Hi Luca and Rajesh, you guys really saved me here. I had been 2 days already with this error, I even asked in the gatsby Discord, but you guys were eventually the saviors!
I think I know what's going on. Gatsby tries to render all the files in
src/pages
as pages. When it gets to the templates that are used bycreatePage
, it freaks out because the context that you passed from is not there (createPage
hasn't been called at this point). So when you move these files to another directory, Gatsby no longer tries to render your templates as pages and only invokes them aftercreatePage
has been called.Does that make sense?
di you find the answer, I really need help