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.
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 by createPage, 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 after createPage has been called.
Does that make sense?
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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?