Bumped deps this morning to pull in the recent gatsby-plugin-sharp fix (#2205) and in doing so I also updated the gatsby package itself. After doing this the React Gatsby site shows the following error while building:
GraphQL Error There was an error while compiling your site's GraphQL queries.
The particular query that starts failing seems to be in the Home template.
o joy I thought was squashed the last of these generic GQL errors. let me pull the branch and try and debug it. I have a sense of what it might be
@bvaughn sorry on fresh pull and install i'm not seeing an error. I checked with the latest gatsby and gatsby-plugin-sharp but everything built without issue.
Did you yarn upgrade-interactive to update the version of gatsby used in www? (I didn't actually commit the bug to our branch.
yup :/ upgraded everything i could
Ahh!!! Okay. I'll try again once #2227 has been released.
☹️ Just tried upgrading to to [email protected] and doing a clean build (eg rm -rf .cache && yarn build) and see:
$ gatsby build
# build stuff ...
GraphQL Error There was an error while compiling your site's GraphQL queries.
This usually means that more than one instance of 'graphql' is installed in your node_modules. Remove all but the top level one or run `npm dedupe` to fix it.
# more build stuff ...
error Building static HTML for pages failed
See our docs page on debugging HTML builds for help https://goo.gl/yL9lND
38 | <TitleAndMetaTags
39 | title={title}
> 40 | ogUrl={`${urlRoot}/${data.markdownRemark.fields.path}`}
| ^
41 | />
42 | <header
43 | css={{
WebpackError: Cannot read property 'markdownRemark' of undefined
- home.js:40 Home.render
src/templates/home.js:40:37
This usually means that more than one instance of 'graphql' is installed in your node_modules. Remove all but the top level one or run
npm dedupeto fix it.
You should yell over at your GraphQL collegues to fix this ;-)
This is probably what's causing the trouble. Either run dedupe as directed. If that doesn't fix it, you can also run find node_modules -name graphql to find the duplicate versions of the package.
It's weird that multiple versions are being required though. If it's Gatsby's fault, we need to sync up the versions of GraphQL we're requiring so only one package is brought in.
This bug doesn't occur (for me at least) unless I update gatsby past v1.9.42
This is why I filed it here instead of yelling at my colleagues 😆
Well it's their fault that GraphQL treats having multiple copies of the package as a bug :-)
But anyways, we digress.
Could you run yarn why graphql and see what packages are depending on graphql and then see what version of GraphQL each depends on?
$ find node_modules -name graphql
node_modules/gatsby-remark-prismjs/node_modules/prismjs/tests/languages/graphql
node_modules/graphql
node_modules/prismjs/tests/languages/graphql
node_modules/relay-compiler/node_modules/graphql
$ yarn why graphql
info This module exists because "gatsby" depends on it.
info Disk size without dependencies: "1.38MB"
info Disk size with unique dependencies: "1.45MB"
info Disk size with transitive dependencies: "1.45MB"
info Number of shared dependencies: 1
Note that if I don't delete the cache dir (eg rm -rf .cache) after updating Gatsby, the build command _warns_ about the duplicate GraphQL but _does not fail_. Deleting the cache dir and re-building causes a failure. (I wonder if this is why you couldn't repro it, @jquense?)
the build command warns about the duplicate GraphQL but does not fail
It does fail — but because the cached query results still exist, the site seems to work.
So it looks like relay-compiler bumped their GraphQL version? Which version of graphql does gatsby and relay-compiler depend on?
the build command warns about the duplicate GraphQL but does not fail
It does fail — but because the cached query results still exist, the site seems to work.
At the risk of sounding pedantic, I _meant_ that the yarn build command does not fail. 😉
I only mentioned it to rule out a possible source of confusion between why Jason and I were seeing different behavior.
re: cache. Gatsby doesn't re-run queries if the data the query touched hasn't changed. E.g. a query pulls data from node 1 and node 1 hasn't changed since the last run so nothing changes. Which is why updating and re-running seems to work.
I meant that the yarn build command does not fail.
Ah, hmmm yeah — that's something we should fix. @jquense has a good plan here: https://github.com/gatsbyjs/gatsby/issues/2087#issuecomment-328618722
We don't want GraphQL errors to cause failure during development but do during builds.
I was trying with npm and it deduped the graphqls for me, i just tried again yarn and am seeing it. I'm not sure sure yarn isn't deduping it tho, the ranges should be compatible for both...
This is an annoying issue that we aren't really sure how to fix apart from making graphql not care about instanceof checks (FYI i have a PR out to fix this but no comments so far on it: https://github.com/graphql/graphql-js/pull/989 if you wanted to voice something ;) )
node_modules/relay-compiler/node_modules/graphql/package.json ~> 0.10.5
node_modules/graphql ~> 0.10.3
I believe I can work around this temporarily by adding the following to package.json:
"resolutions": {
"gatsby/graphql": "0.10.5"
}
if you wanted to voice something
@jquense he does sit right next to them… ;-)
poke em for me ;)
if you wanted to voice something
@jquense he does sit right next to them… ;-)
Technically I sit about 20 yards away from them, but I have never actually _talked_ to any of them. 😉
However, I will post a link to your PR on the internal forum and mention this. 😄
Print out @jquense's PR and crumple it up and throw it over their direction :-)
lol
It would be nice to fix cause it's one of the most common problems people run into with Gatsby.
I can see why.
Okedoke! I've posted internally with a description of what happened and a link to the PR. 🤞
In the meanwhile, thank you both for your help!
(Should I go ahead and close this? Or should we leave it open and update Gatsby to match the graphql version for now to avoid other people hitting the snag too?)
Awesome!
Yeah update gatsby too if you could. Yarn I guess is pickier about deduping than NPM.
I'm getting the same error. When I run npm dedupe, it responds with npm ERR! Cannot read property 'length' of undefined (the full log for the error is here). Adding the resolutions entry above doesn't fix the queries.
Closing this issue as it's fairly old and we have far too many open issues! If you have additional problems in this area, please open a new issue!
it work on localhist but when i upload on netlify then got error:
error There was an error in your GraphQL query:
Unknown type "ContentfulFixed".
Most helpful comment
However, I will post a link to your PR on the internal forum and mention this. 😄