简体   繁体   中英

./node_modules/react-router-dom/node_modules/warning/warning.js Error: ENOENT: no such file or directory, open

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 ( rm -rf ) from your project directory and run yarn install again.

Once I had this issue and I tried stopping all the Node processes in the process explorer. Also, try to install the package from a command line tool.

This resolved the issue for me.

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): 在此处输入图片说明

我在 react & laravel 项目中更新了一些 npm 包时遇到了同样的问题,所以我所做的就是使用命令 npm start 重新启动 react,问题解决了。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM