Cannot Resolve Module 'react-dom'
Answer :
Issue is react-dom
is not installed, when you hit npm -v react-dom
, it gives you the version of npm
not react-dom
version, you can check that by using npm -v
or npm -v react-dom
both will give you the same result. You are checking the package version incorrectly.
How to install react and react-dom properly?
Use this to install react and react-dom:
npm install react react-dom --save
After that, you can check your package.json
file, if react and react-dom has been installed correctly, you will find an entry for that.
How to check install package version?
To check all the locally installed packages version:
npm list
For globally installed packages, use -g also:
npm list -g
To check the version of any specific package, specify the package name also:
npm list PackageName For Example => npm list react npm list react-router
After installation your package.json
will look like this:
{ "name": "***", "version": "1.0.0", "main": "***", "scripts": { .... }, "repository": { .... }, "keywords": [], "author": "", "dependencies": { .... "react": "^15.4.2", //react "react-dom": "^15.4.2", //react-dom .... }, "devDependencies": { .... } }
Latest version of react-dom
is : 15.4.2
Reference: https://www.npmjs.com/package/react-dom
In my case I had an alias in my webpack.config.common.js:
resolve: { extensions: ['.js', '.jsx'], alias: { 'react-dom': '@hot-loader/react-dom', }, },
I just removed this line:
'react-dom': '@hot-loader/react-dom',
and it was fixed.
For anybody reading this that wasn't able to figure it out. I had the same issue which I ended up resolving by installing the "react-router" package which is simply running the following command
npm i react-router-dom --save
for a browser app.
npm i react-router-native
for a native app.
Comments
Post a Comment