question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: Cannot find module 'gatsby/graphql' when trying to run 'gatsby develop'

See original GitHub issue

Summary

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:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
LekoArtscommented, May 4, 2020

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-images you need to have gatsby-plugin-sharp installed and in your gatsby-config.js, for gatsby-image you also need gatsby-transformer-sharp set up. I’d advise to delete the /Users/eric/node_modules folder, delete /Users/eric/personal-blog/node_modules/ and install the two dependencies (and put them into gatsby-config.js) and run a fresh npm install. Then also do a gatsby clean / rm -rf .cache public in 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!

1reaction
Js-Brechtcommented, May 3, 2020

These two lines appear to be the problem:

  - /Users/eric/node_modules/gatsby-transformer-sharp/customize-schema.js
  - /Users/eric/node_modules/gatsby-transformer-sharp/gatsby-node.js

So you have something registering gatsby-transformer-sharp; my guess would be that it’s in your gatsby-config.js. But, like @capndave mentioned, you don’t have gatsby-transformer-sharp installed in your project. Instead, it is installed in some node_modules in the root of your home directory.

When Gatsby scans your gatsby-config.js and sees gatsby-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-sharp attempts to require() gatsby/graphql, it is going to start in its own directory, then travel up the file tree. If it doesn’t find gatsby in that direction, it fails. As you can see, gatsby is installed below where gatsby-transformer-sharp is installed.

/Users/eric/personal-blog/node_modules/gatsby/

My suggestion would be to install gatsby-transfomer-sharp in your project. My other suggestion would be to not keep a “root” node_modules like that, because that can frequently cause some weird issues like this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: Cannot find module 'gatsby-plugin-image/graphql-utils'
When I ran into this issue I found that adding the new package gatsby-plugin-image fixed it. The README for gatsby-source-contentful has a ...
Read more >
Troubleshooting Common Errors - Gatsby
comes up when a GraphQL query is trying to query a field for subfields, but none exist. This generally happens when plugins that...
Read more >
[ gatsby ] Error: Cannot find module 'gatsby/graphql' - dsin
Problem Solution install v1 instead of v2 ref : https://github.com/gatsbyjs/gatsby/issues/6560.
Read more >
Gatsby Changelog | 5.3.0
ES Modules (ESM) in Gatsby files; Improved error messages ... Gatsby uses child processes to execute its GraphQL queries in parallel (with its...
Read more >
Error with module gatsby-source-prismic-graphql
Hi all, The installation of the module gatsby-source-prismic-graphql return an error : Error: Cannot find module './third-party/gatsby-node' ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found