Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Cannot find module 'react' - after installing Plugin #18048

Closed
muescha opened this issue Oct 2, 2019 · 37 comments
Closed

Error: Cannot find module 'react' - after installing Plugin #18048

muescha opened this issue Oct 2, 2019 · 37 comments

Comments

@muescha
Copy link
Contributor

muescha commented Oct 2, 2019

Description

When i followed the documentation i get an error. as @marcysutton suggested in #17318 (comment) i file a new issue about this.

Steps to reproduce

i followed the receipt (in draft) in #17318

steps i have done:

npm install -g gatsby-cli
gatsby new gatsby-site-contentful2
cd gatsby-site-contentful2/
gatsby develop
gatsby build
gatsby serve
# in this case leave off the contentful cli commands
npm install --save gatsby-source-contentful
nano gatsby-config.js  # add tokens
gatsby develop         # error
npm install
gatsby develop

Expected result

no error - i should be able to run gatsby develop

Actual result

here is got the error:

 ERROR                                                                                                                                                                                                   
                                                                                                                                                                                                         
There was a problem loading the local develop command. Gatsby may not be installed. Perhaps you need to run "npm install"? Cannot find module 'react'                                                    
                                                                                                                                                                                                         
                                                                                                                                                                                                         
                                                                                                                                                                                                         
  Error: Cannot find module 'react'                                                                                                                                                                      
                                                                                                                                                                                                         
  - loader.js:582 Function.Module._resolveFilename                                                                                                                                                       
    internal/modules/cjs/loader.js:582:15                                                                                                                                                                
                                                                                                                                                                                                         
  - loader.js:508 Function.Module._load                                                                                                                                                                  
    internal/modules/cjs/loader.js:508:25 

	[...]                                                                                                                                                               

i could solved it with npm install - should we add it in this receipt to avoid confusing error messages?

(after the install of the starter in Prerequisites i was able to run gatsby develop without error - we should add if after the step which requires a new npm install)

Workaround

runnning npm install

the npm install gives me this output and i see there are new packages installed and changed:

npm install
                                                                                                                                                                                                                                                                                                     
> gatsby@2.15.28 postinstall /Users/muescha/Work/gatsby/gatsby-site-contentful2/node_modules/gatsby                                                                                                                                                                                                  
> node scripts/postinstall.js                                                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                                                     
npm WARN eslint-config-react-app@4.0.1 requires a peer of eslint-plugin-flowtype@2.x but none is installed. You must install peer dependencies yourself.                                                                                                                                             
npm WARN tsutils@3.17.1 requires a peer of typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta but none is installed. You must install peer dependencies yourself.                                  
                                                                                                                                                                                                                                                                                                     
added 5 packages from 2 contributors, removed 5 packages, updated 13 packages and audited 28684 packages in 17.208s                                                                                                                                                                                  
found 0 vulnerabilities 

Environment

  System:
    OS: macOS 10.14.5
    CPU: (8) x64 Intel(R) Core(TM) i7-3820QM CPU @ 2.70GHz
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 10.15.3 - ~/.nvm/versions/node/v10.15.3/bin/node
    Yarn: 1.17.3 - /usr/local/bin/yarn
    npm: 6.11.3 - ~/.nvm/versions/node/v10.15.3/bin/npm
  Languages:
    Python: 2.7.16 - /usr/local/bin/python
  Browsers:
    Chrome: 77.0.3865.90
    Safari: 12.1.1
  npmPackages:
    gatsby: ^2.15.28 => 2.15.28 
    gatsby-image: ^2.2.23 => 2.2.23 
    gatsby-plugin-manifest: ^2.2.20 => 2.2.20 
    gatsby-plugin-offline: ^3.0.11 => 3.0.11 
    gatsby-plugin-react-helmet: ^3.1.10 => 3.1.10 
    gatsby-plugin-sharp: ^2.2.27 => 2.2.27 
    gatsby-source-contentful: ^2.1.44 => 2.1.44 
    gatsby-source-filesystem: ^2.1.28 => 2.1.28 
    gatsby-transformer-sharp: ^2.2.19 => 2.2.19 
  npmGlobalPackages:
    gatsby-cli: 2.7.53
@jonniebigodes
Copy link

Just tested it and the error pops up. But it does not pop up when using yarn.

@muescha
Copy link
Contributor Author

muescha commented Oct 2, 2019

but docs all in npm :/

@jonniebigodes
Copy link

just pointing it out, to provide some more context.

@a-rbsn
Copy link

a-rbsn commented Oct 20, 2019

I am also running into this error

@DanielRuf
Copy link
Contributor

This might be because npm calculates the deptree differently.

Does this also happen with the latest release of npm?

@LekoArts
Copy link
Contributor

LekoArts commented Nov 4, 2019

I also tried it with the latest version of npm without luck. yarn always works fine. But since this is definitely an issue with npm there isn't much we can do about it.

Changing our whole documentation (since a lot of pages tell you to install something and then run gatsby develop) is not an option as this might easily get outdated quickly (by npm fixing this issue) and then we have a lot of unnecessary churn in our docs.

Hence I'm closing this issue. Thanks for opening it though, hope npm fixes this soon!

@muescha
Copy link
Contributor Author

muescha commented Nov 4, 2019

Is there an npm issue filed about this?

@muescha
Copy link
Contributor Author

muescha commented Nov 4, 2019

But now the users have this problem.

I think we should add a note to the docs (maybe as hint) so that new users don't get confused and not have a bad onboarding experience.

If this is fixed by npm we can remove this hint later.

@mynameisthunder
Copy link

Ya I started a new gatsby project (around my 4th one, but havent had a new one in months), updated everything and then all shit went to hell. Does anyone know when there will be a npm fix or do we all just have to start using yarn

@bruno-vaz
Copy link

I'm having the problem even if I use yarn.
Created new hello-world project, deleted node_modules and package-lock.json, ran yarn install and then yarn add with these packages:

  • gatsby-plugin-sass
  • gatsby-plugin-root-import
  • gatsby-plugin-react-helmet
  • gatsby-plugin-web-font-loader
  • gatsby-plugin-google-tagmanager

image

Now I'm getting around by copying another project's files (without node_modules folder), installing the dependencies and modifying it.
Problem seems to be when a package is added, not in the installation step.

@richardhealy
Copy link

This occurred for me when I added gatsby-plugin-sass via npm. The following steps helped fix the issue:

  • rm -Rf node_modules package-lock.json
  • yarn install

Seemed to bring it back to life. The docs mention npm everywhere (Dec 2019), but I'm guessing we need to use yarn for plugin installation.

@ghost
Copy link

ghost commented Jan 22, 2020

This is still an issue.

Fresh install of Gatsby Default Starter, then npm install --save gatsby-plugin-styled-components styled-components babel-plugin-styled-components

Produces the same errors as described above.

yarn add gatsby-plugin-styled-components styled-components babel-plugin-styled-components does not produce the error.

@KVexcavator
Copy link

I will fix it - npm install core-js@3

@DanielRuf
Copy link
Contributor

I will fix it - npm install core-js@3

How is this related to react?

@zedrickvillas
Copy link

This occurred for me when I added gatsby-plugin-sass via npm. The following steps helped fix the issue:

  • rm -Rf node_modules package-lock.json
  • yarn install

Seemed to bring it back to life. The docs mention npm everywhere (Dec 2019), but I'm guessing we need to use yarn for plugin installation.

This worked for me. Thanks!
I guess the onboarding/tutorial document needs to be updated to support both npm and yarn.

@hcgaron
Copy link

hcgaron commented Mar 4, 2020

This is a massive productivity killer. I've spent the last hour trying to bring my STARTER to life, just to add styled components! Docs need to reflect this IMO.

@muescha
Copy link
Contributor Author

muescha commented Mar 5, 2020

since this problems are not sticked to special receipt, maybe it would be good to hava a faq section or most common problems with the recipes and how to solve this?

@djasuncion
Copy link

I(new to gatsby) just got this problem for a new install. Sadly, I'm going back to CRA for now.

@xansibar
Copy link

xansibar commented May 8, 2020

I also had the same issue, probably after installing the plugin gatsby-plugin-sass.

My workaround was this:

npm install
npm audit fix
npm run develop

Cheers!

@domsbytes
Copy link

I also had same issue after installing gatsby-plugin-sass. Used richardhealy solution above to fix.

@skube
Copy link
Contributor

skube commented Jul 4, 2020

I would just like say that while it's an issue with npm, it is still a potential roadblock for new users.

Consider this flow:

❯ gatsby new
✔ What is your project called? … my-very-first-gatsby
✔ What starter would you like to use? › gatsby-starter-hello-world
...
Your new Gatsby site has been successfully bootstrapped. Start developing it by running:

  cd my-very-first-gatsby
  gatsby develop

❯ cd my-very-first-gatsby
❯ gatsby develop

# (...Great! Works! let's add some images)

❯ npm install gatsby-image
❯ gatsby develop

**ERROR ERROR**

There was a problem loading the local develop command.
Gatsby may not be installed.
Perhaps you need to run "npm install"? Cannot find module 'react'

**Error: Cannot find module 'react'**

#(hmm...ok let's do what it says, run `npm install`)

❯ npm install
...
❯ gatsby develop

**Error: Invalid hook call. **
Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
  1. You might have mismatching versions of React and the renderer (such as React DOM)
  2. You might be breaking the Rules of Hooks
  3. You might have more than one copy of React in the same app
  See https://fb.me/react-invalid-hook-call for tips about how to debug and fix this problem.

# wtf
#?!?#!

That's a terrible experience.

@gonbaum
Copy link

gonbaum commented Jul 7, 2020

Just installed default started, everything worked until I used npm install react-bootstrap
Then
Error: Cannot find module 'react'
Npm install installs 2 version of react so then the next thing is that I get a new error:
Error: Invalid hook call. in StoreStateProvider
Runned npm ls react and theres is 2 react packages installed, there are many issues on this, no clear solution yet. I'm losing too much time to just get started. I'm now trying with npm uninstall react react-dom gatsby and then re-installing them. If it doesn't work I will try to switch to Yarn.

@theship
Copy link

theship commented Jul 9, 2020

Today, I had this error when installing Airtable plugin. I went to search for this issue and came across Issue #25556. So I tried to walk through the tutorials, and sure enough, I was able to replicate this error when reviewing https://www.gatsbyjs.org/tutorial/part-three/.

At https://www.gatsbyjs.org/tutorial/part-three/, I ran into the problem:

  1. Did step 1 and installed "tutorial-part-three"
  2. Ran "gatsby develop" to confirm I had success.
  3. Stopped the server and installed gatsby-plugin-typography, according to step 1 of the tut.
  4. Ran "gatsby develop"

ACTUAL:

  Error: Cannot find module 'react'
  Require stack:

  Error: Cannot find module 'react'
  Require stack:
  - /Users/someuser/GitHub/a-test-folder/tutorial-part-three/node_modules/ink/build/instance.js
  - /Users/someuser/GitHub/a-test-folder/tutorial-part-three/node_modules/ink/build/render.js
  - /Users/someuser/GitHub/a-test-folder/tutorial-part-three/node_modules/ink/build/index.js
  - /Users/someuser/GitHub/a-test-folder/tutorial-part-three/node_modules/gatsby/node_modules/gat  sby-cli/lib/reporter/loggers/ink/index.js
  - /Users/someuser/GitHub/a-test-folder/tutorial-part-three/node_modules/gatsby/node_modules/gat  sby-cli/lib/reporter/start-logger.js
  - /Users/someuser/GitHub/a-test-folder/tutorial-part-three/node_modules/gatsby/node_modules/gat  sby-cli/lib/reporter/index.js
  - /Users/someuser/GitHub/a-test-folder/tutorial-part-three/node_modules/gatsby/dist/commands/de  velop.js
  - /Users/someuser/.nvm/versions/node/v14.4.0/lib/node_modules/gatsby-cli/lib/create-cli.js
  - /Users/someuser/.nvm/versions/node/v14.4.0/lib/node_modules/gatsby-cli/lib/index.js
  - /Users/someuser/.nvm/versions/node/v14.4.0/lib/node_modules/gatsby-cli/cli.js
  
  - loader.js:1029 Function.Module._resolveFilename
    internal/modules/cjs/loader.js:1029:15
  
  - loader.js:898 Function.Module._load
    internal/modules/cjs/loader.js:898:27
  
  - loader.js:1089 Module.require
    internal/modules/cjs/loader.js:1089:19
  
  - helpers.js:73 require
    internal/modules/cjs/helpers.js:73:18
  
  - instance.js:8 Object.<anonymous>
    [tutorial-part-three]/[ink]/build/instance.js:8:37
  
  - loader.js:1200 Module._compile
    internal/modules/cjs/loader.js:1200:30
  
  - loader.js:1220 Object.Module._extensions..js
    internal/modules/cjs/loader.js:1220:10
  
  - loader.js:1049 Module.load
    internal/modules/cjs/loader.js:1049:32
  
  - loader.js:937 Function.Module._load
    internal/modules/cjs/loader.js:937:14
  

Ran npm ls react:

gatsby-starter-hello-world@0.1.0 /Users/someuser/GitHub/a-test-folder/tutorial-part-three
└─┬ gatsby@2.23.12
  └─┬ UNMET DEPENDENCY gatsby-cli@2.12.52
    └── UNMET DEPENDENCY react@16.13.1 

npm ERR! missing: gatsby-cli@2.12.52, required by gatsby@2.23.12
npm ERR! missing: react@16.13.1, required by gatsby-cli@2.12.52

@richardhealy Workaround worked:

rm -Rf node_modules package-lock.json
yarn install

@skube
Copy link
Contributor

skube commented Jul 9, 2020

Doing a "fresh" install will work with Yarn or npm:

rm -rf node_modules package-lock.json

npm install
# OR
yarn

(altho deleting the lock file could have undesirable effects as it will remove the version "lock" on all packages — allowing them to update the highest semver defined in package.json)

@DanielRuf
Copy link
Contributor

rm -rf node_modules package-lock.json

npm install
# OR
yarn

You can also use npm ci (cleaninstall) ;-)

@skube
Copy link
Contributor

skube commented Jul 9, 2020

@DanielRuf That's what I thought at first too, but I tried it and it didn't work for me:

❯ gatsby new try-ci  https://github.com/gatsbyjs/gatsby-starter-hello-world
❯ cd try-ci
❯ gatsby develop
# (all good)
❯ npm i gatsby-image
❯ gatsby develop
# (errors)
❯ npm ci
# (still errors)

@DanielRuf
Copy link
Contributor

What npm version do you use? The latest versions should work better. But I guess your problem is solved now. Just wanted to mention npm ci which helped in our projects so far before we migrated all projects to yarn at one company.

@skube
Copy link
Contributor

skube commented Jul 9, 2020

❯ npm -v
6.14.5

@Marvelousy20
Copy link

Oh yeah, gatsby needs to fix up. I was almost giving up as a new user.

@blyatmobilebr-zz
Copy link

I'm facing the same issue after installing gatsby-plugin-sass and node-sass. I hope they fix this bug if it's related to Gatsby.

@isaialejandro
Copy link

Trying to resolve this error, i find yarn better for installing plugins in my <> gatsby project.
It´s necessary:

1.- remove the package-lock.json
2.- yarn install
3.- gatsby develop
4.- don´t use fcking npm ´couse it breaks. (i don´t know why and i wanna know why is this npm issue happening)
5.- yarn install.

If you need yo add more plugins, try with: "yarn add gatsby-plugin-page-creator" instead "npm install --save gatsby-plugin-page-creator"

Hope this little info works for ya!

@DenisCor
Copy link

DenisCor commented Sep 4, 2020

installed today react-bootsrap and I get the same error. Fix your shit ffs!

@wardpeet
Copy link
Contributor

This issue should have been resolved in the latest gatsby-cli. If you already had it before please run the following command:

gatsby-cli options set pm npm

This will reset gatsby-cli to using npm and not yarn

@ncarchedi
Copy link

gatsby-cli options set pm npm

@wardpeet shouldn't that be this?

gatsby options set pm npm

@JasperCiti
Copy link

Still getting this error with the latest Gatsby and tutorial.

@Peach-24
Copy link

Peach-24 commented Feb 4, 2021

New to gatsby - working through the official tutorial and encountered this error, just before I got this far (https://www.gatsbyjs.com/docs/tutorial/part-four/#your-first-graphql-query)

`Generating development SSR bundle failed

Can't resolve
'/Users/joshpeachey/dev/sandbox/tutorial-part-four/src/utils/typography'
in '/Users/joshpeachey/dev/sandbox/tutorial-part-four/.cache/caches/gatsb
y-plugin-typography'

If you're trying to use a package make sure that
'/Users/joshpeachey/dev/sandbox/tutorial-part-four/src/utils/typography'
is installed. If you're trying to use a local file make sure that the
path is correct.

File: .cache/caches/gatsby-plugin-typography/typography.js`

@faranak6
Copy link

Error: Cannot find module 'C:\Users\create-react-app\index.js'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}

C:\Users\faranak&hassan\Desktop>cd ..

C:\Users\faranak&hassan>npm install ../faye
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path C:\Users\faye/package.json
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\faye\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\faranak&hassan\AppData\Local\npm-cache_logs\2021-11-27T03_14_22_776Z-debug.log

C:\Users\faranak&hassan>npm install -g create-react-app
npm notice Beginning October 4, 2021, all connections to the npm registry - including for package installation - must use TLS 1.2 or higher. You are currently using plaintext http to connect. Please visit the GitHub blog for more information: https://github.blog/2021-08-23-npm-registry-deprecating-tls-1-0-tls-1-1/
npm notice Beginning October 4, 2021, all connections to the npm registry - including for package installation - must use TLS 1.2 or higher. You are currently using plaintext http to connect. Please visit the GitHub blog for more information: https://github.blog/2021-08-23-npm-registry-deprecating-tls-1-0-tls-1-1/
npm WARN deprecated tar@2.2.2: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap.

changed 67 packages in 17s

4 packages are looking for funding
run npm fund for details

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests