Error: Cannot find module 'gatsby/graphql' when trying to run 'gatsby develop'
See original GitHub issueSummary
When I try to run ‘gatsby develop’ I get the error 'Cannot find module ‘gatsby/graphql’.
Relevant information
I set up a new gatsby project; changed some files and was able to run ‘gatsby develop’.
I added a few gatsby plugins to my project and now I run into this error.
I already had a look at the following issues but I either did not understand the solution not well enough or they do not work for this issue. #8249 #8478 #20841 #22990
Environment
System: OS: macOS Mojave 10.14.6 CPU: (4) x64 Intel® Core™ i5-7360U CPU @ 2.30GHz Shell: 3.2.57 - /bin/bash Binaries: Node: 14.1.0 - /usr/local/bin/node npm: 6.14.4 - /usr/local/bin/npm Languages: Python: 2.7.10 - /usr/bin/python Browsers: Chrome: 81.0.4044.129 Safari: 13.0.1 npmPackages: gatsby: ^2.13.13 => 2.21.0 gatsby-image: ^2.4.0 => 2.4.0 gatsby-plugin-catch-links: ^2.3.0 => 2.3.0 gatsby-plugin-feed: ^2.5.0 => 2.5.0 gatsby-plugin-google-analytics: ^2.3.0 => 2.3.0 gatsby-plugin-manifest: ^2.2.1 => 2.4.0 gatsby-plugin-netlify: ^2.3.0 => 2.3.0 gatsby-plugin-nprogress: ^2.3.0 => 2.3.0 gatsby-plugin-react-helmet: ^3.1.0 => 3.1.0 gatsby-plugin-sass: ^2.3.0 => 2.3.0 gatsby-plugin-sitemap: ^2.2.1 => 2.2.1 gatsby-remark-autolink-headers: ^2.3.0 => 2.3.0 gatsby-remark-copy-linked-files: ^2.3.1 => 2.3.1 gatsby-remark-images: ^3.1.3 => 3.1.3 gatsby-remark-prismjs: ^3.3.1 => 3.3.1 gatsby-source-filesystem: ^2.0.23 => 2.3.0 gatsby-transformer-remark: ^2.6.2 => 2.6.2 npmGlobalPackages: gatsby-cli: 2.12.7
File contents
(most of the requested files are too long to be included here, but I can post them in a follow-up if necessary!)
Error message terminal
Error: Cannot find module 'gatsby/graphql'
Require stack:
- /Users/eric/node_modules/gatsby-transformer-sharp/customize-schema.js
- /Users/eric/node_modules/gatsby-transformer-sharp/gatsby-node.js
- /Users/eric/personal-blog/node_modules/gatsby/dist/bootstrap/resolve-module-exports.js
- /Users/eric/personal-blog/node_modules/gatsby/dist/bootstrap/load-plugins/validate.js
- /Users/eric/personal-blog/node_modules/gatsby/dist/bootstrap/load-plugins/load.js
- /Users/eric/personal-blog/node_modules/gatsby/dist/bootstrap/load-plugins/index.js
- /Users/eric/personal-blog/node_modules/gatsby/dist/bootstrap/index.js
- /Users/eric/personal-blog/node_modules/gatsby/dist/commands/develop.js
- /usr/local/lib/node_modules/gatsby-cli/lib/create-cli.js
- /usr/local/lib/node_modules/gatsby-cli/lib/index.js
- loader.js:1020 Function.Module._resolveFilename
internal/modules/cjs/loader.js:1020:15
- loader.js:890 Function.Module._load
internal/modules/cjs/loader.js:890:27
- loader.js:1080 Module.require
internal/modules/cjs/loader.js:1080:19
- v8-compile-cache.js:159 require
[personal-blog]/[v8-compile-cache]/v8-compile-cache.js:159:20
- customize-schema.js:13 Object.<anonymous>
[eric]/[gatsby-transformer-sharp]/customize-schema.js:13:5
- v8-compile-cache.js:178 Module._compile
[personal-blog]/[v8-compile-cache]/v8-compile-cache.js:178:30
- loader.js:1196 Object.Module._extensions..js
internal/modules/cjs/loader.js:1196:10
- loader.js:1040 Module.load
internal/modules/cjs/loader.js:1040:32
- loader.js:929 Function.Module._load
internal/modules/cjs/loader.js:929:14
- loader.js:1080 Module.require
internal/modules/cjs/loader.js:1080:19
- v8-compile-cache.js:159 require
[personal-blog]/[v8-compile-cache]/v8-compile-cache.js:159:20
- gatsby-node.js:4 Object.<anonymous>
[eric]/[gatsby-transformer-sharp]/gatsby-node.js:4:37
- v8-compile-cache.js:178 Module._compile
[personal-blog]/[v8-compile-cache]/v8-compile-cache.js:178:30
- loader.js:1196 Object.Module._extensions..js
internal/modules/cjs/loader.js:1196:10
- loader.js:1040 Module.load
internal/modules/cjs/loader.js:1040:32
- loader.js:929 Function.Module._load
internal/modules/cjs/loader.js:929:14
- loader.js:1080 Module.require
internal/modules/cjs/loader.js:1080:19
- v8-compile-cache.js:159 require
[personal-blog]/[v8-compile-cache]/v8-compile-cache.js:159:20
- resolve-module-exports.js:134 module.exports
[personal-blog]/[gatsby]/dist/bootstrap/resolve-module-exports.js:134:26
- validate.js:120
[personal-blog]/[gatsby]/dist/bootstrap/load-plugins/validate.js:120:31
- Array.forEach
- validate.js:113 collatePluginAPIs
[personal-blog]/[gatsby]/dist/bootstrap/load-plugins/validate.js:113:20
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)

Top Related StackOverflow Question
Thank you for opening this!
As Jeremy pointed out you’re missing some dependencies and/or they are in the wrong folders. When you use
gatsby-remark-imagesyou need to havegatsby-plugin-sharpinstalled and in your gatsby-config.js, forgatsby-imageyou also needgatsby-transformer-sharpset up. I’d advise to delete the/Users/eric/node_modulesfolder, delete/Users/eric/personal-blog/node_modules/and install the two dependencies (and put them into gatsby-config.js) and run a freshnpm install. Then also do agatsby clean/rm -rf .cache publicin case the old fragments are saved into Gatsby.We’re marking this issue as answered and closing it for now but please feel free to comment here if you would like to continue this discussion. We also recommend heading over to our communities if you have questions that are not bug reports or feature requests. We hope we managed to help and thank you for using Gatsby!
These two lines appear to be the problem:
So you have something registering
gatsby-transformer-sharp; my guess would be that it’s in yourgatsby-config.js. But, like @capndave mentioned, you don’t havegatsby-transformer-sharpinstalled in your project. Instead, it is installed in somenode_modulesin the root of your home directory.When Gatsby scans your
gatsby-config.jsand seesgatsby-transformer-sharp, it will ask Node to resolve the path; since it is above Gatsby in your filesystem, Node’s able to find it.However, when
gatsby-transformer-sharpattempts torequire()gatsby/graphql, it is going to start in its own directory, then travel up the file tree. If it doesn’t findgatsbyin that direction, it fails. As you can see,gatsbyis installed below wheregatsby-transformer-sharpis installed.My suggestion would be to install
gatsby-transfomer-sharpin your project. My other suggestion would be to not keep a “root”node_moduleslike that, because that can frequently cause some weird issues like this.