Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create-React-App: ESlint error while deployment on local machine

I am using create-react-app (React v16.12.0). I am getting following error when I run 'npm start' on mac.

[1] There might be a problem with the project dependency tree.
[1] It is likely not a bug in Create React App, but something you need to fix locally.
[1]
[1] The react-scripts package provided by Create React App requires a dependency:
[1]
[1]   "eslint": "^6.6.0"
[1]
[1] Don't try to install it manually: your package manager does it automatically.
[1] However, a different version of eslint was detected higher up in the tree:
[1]
[1]   /Users/abz/node_modules/eslint (version: 6.5.1)
[1]
[1] Manually installing incompatible versions is known to cause hard-to-debug issues.
[1]
[1] If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
[1] That will permanently disable this message but you might encounter other issues.
[1]
[1] To fix the dependency tree, try following the steps below in the exact order:
[1]
[1]   1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
[1]   2. Delete node_modules in your project folder.
[1]   3. Remove "eslint" from dependencies and/or devDependencies in the package.json file in your project folder.
[1]   4. Run npm install or yarn, depending on the package manager you use.
[1]
[1] In most cases, this should be enough to fix the problem.
[1] If this has not helped, there are a few other things you can try:
[1]
[1]   5. If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead.
[1]      This may help because npm has known issues with package hoisting which may get resolved in future versions.
[1]
[1]   6. Check if /Users/abz/node_modules/eslint is outside your project directory.
[1]      For example, you might have accidentally installed something in your home folder.
[1]
[1]   7. Try running npm ls eslint in your project folder.
[1]      This will tell you which other package (apart from the expected react-scripts) installed eslint.
[1]
[1] If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
[1] That would permanently disable this preflight check in case you want to proceed anyway.
[1]
[1] P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!
[1]
[1] react-scripts start exited with code 1

I googled and found

  1. following solution suggested by many

    • Delete the eslint and babel-eslint from users/abz/node_modules/folder
    • Delete package.json-lock, node_modules from local project
    • Run npm install and npm start

    I tried it and this solution didn't work for me.

  2. This issue can be mitigated by using

    adding an `.env file` in root folder with statement `SKIP_PREFLIGHT_CHECK=true` 
    

    But, it is not the solution for this problem.

Any help?

like image 466
AbyKal Avatar asked Feb 08 '20 07:02

AbyKal


People also ask

How do I fix ESLint errors in react?

Fixing Multiple Errors ESLint has a feature where you enter the file path and eslint --fix and it automatically fixes every simple error that won't cause a dumpster fire in our project. To try this in our current project, run the following from your terminal: ./node_modules/eslint/bin/eslint. js --fix src/App.

Do you need to install ESLint With create react app?

Note, ESLint is installed with create-react-app, so you don't need to explicitly install it. Then install the packages for Airbnb config. This command will work for Yarn or NPM.


3 Answers

it happens because there is a dependency installed at a parent level which has different version. In your case it's /Users/abz/node_modules/eslint. Just run this command from root

rm -rf node_modules/eslint

and this should solve your problem.

like image 147
Anuj Shah Avatar answered Oct 18 '22 21:10

Anuj Shah


following Anuj shah & SHAHBAZ replies:

  1. rm -rf node_modules/eslint
  2. npm install -g npm@latest

or just do npm i -S fsevents

resolved this issue.

but i have to do the above steps again and again whenever i install another package. this is so frustrating...

does anyone have a better solution for this?

like image 38
Vivek22 Avatar answered Oct 18 '22 20:10

Vivek22


I've done the following steps and solved the problem...

  1. Delete node_modules, package-lock.json / yarn.lock
  2. Add "eslint": "^6.6.0" to your devDependencies
  3. Run npm install / yarn
  4. Run the eslint --init command
  5. Install the eslint plugins you need
like image 44
Luan Träsel Avatar answered Oct 18 '22 19:10

Luan Träsel