Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Module not found: Can't resolve 'react'

I'm trying to connect my Redux store to my React project, but I keep getting this error:

../node_modules/react-redux/es/components/Provider.js Module not found: Can't resolve 'react' in 'C:\Users.\Documents..\node_modules\react-redux\es\components'

I've installed both react-redux and redux (I believe react-redux has some dependencies on redux)

import { Provider} from 'react-redux';

This is what is giving the error.

Any suggestions on what I could do?

like image 509
econCodergirl Avatar asked Aug 31 '19 18:08

econCodergirl


People also ask

How do you fix module not found Cannot resolve in react?

To solve the "Module not found: Can't resolve" error in React, make sure to install the package from the error message if it's a third-party package, e.g. npm i somePackage . If you got the error when importing local files, correct your import path.

How do I import createRoot into react?

import React from 'react'; import ReactDOM from 'react-dom'; import { createRoot } from 'react-dom/client'; import Switch from './components/Switch'; const root = ReactDOM. createRoot(document. getElementById('root')); root. render( <React.


2 Answers

This could be caused by your node_modules

At the first delete your node_modules, package-lock.json, yarn.lock then install all dependencies again

like rm -rf node_modules rm -rf package-lock.json rm -rf yarn.lock

then run

npm install

like image 115
ANIK ISLAM SHOJIB Avatar answered Nov 15 '22 11:11

ANIK ISLAM SHOJIB


Please import react at top

import React from 'react'

like image 44
jamal Avatar answered Nov 15 '22 09:11

jamal