I install yarn add react-router-dom and it shows error when import "react-router-dom"
Error message
./node_modules/react-router-dom/node_modules/warning/warning.js
Error: ENOENT: no such file or directory, open '/Users/krittiyaclark/Documents/my-portfolio-react/node_modules/react-router-dom/node_modules/warning/warning.js'
My package.json
{
"name": "my-portfolio-react",
"version": "0.1.0",
"private": true,
"dependencies": {
"gulp": "^3.9.1",
"gulp-changed": "^3.2.0",
"gulp-clean-css": "^4.0.0",
"gulp-rename": "^1.4.0",
"gulp-sass": "^4.0.2",
"gulp-uglify": "^3.0.1",
"react": "^16.7.0",
"react-dom": "^16.7.0",
"react-mdl": "^1.11.0",
"react-router-dom": "^4.3.1",
"react-scripts": "2.1.3"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
Please help! I stuck for a long time. Thank you!
If you haven't run yarn install yet, you need to run it to install all your dependencies. If you have installed them before, delete .cache directory from your project directory (rm -rf .cache) and run yarn install again.
I just created an app with create-react-app and added react-router-dom as you did and everything is working fine, the only differences that I have are some package versions:
{
"name": "quicktest",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.8.4",
"react-dom": "^16.8.4",
"react-router-dom": "^4.3.1",
"react-scripts": "2.1.8"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
Try to run npm update to update them and restart your app.
Also, apparently, the release 4.3.1 of react-router-dom fixed something related to this error (What's odd is this is the version that you're using):

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With