Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

eslint in terminal Cannot find module 'eslint-config-react-app'

I use create-react-app to make a react app.

the linter works in create-react-app but now i want make it work in my sublimetext.

  1. Installed eslint yarn global add eslint (eslint v4.1.1 but also tried v3.19.0 because react app uses that one)
  2. run eslint --init and configured it
  3. go to directory of project and made a file called .eslintrc
  4. inside file:
{
"extends": "react-app"
}
  1. run in project directory eslint src/App.js
  2. get error in terminal :

    Referenced from: /mnt/storage/Dev/newapp/.eslintrc Error: Cannot find module 'eslint-config-react-app'

    Referenced from: /mnt/storage/Dev/newapp/.eslintrc at ModuleResolver.resolve (/home/user/.config/yarn/global/node_modules/eslint/lib/util/module-resolver.js:74:19) at resolve (/home/user/.config/yarn/global/node_modules/eslint/lib/config/config-file.js:515:25) at load (/home/user/.config/yarn/global/node_modules/eslint/lib/config/config-file.js:584:26) at configExtends.reduceRight (/home/user/.config/yarn/global/node_modules/eslint/lib/config/config-file.js:421:36) at Array.reduceRight (native) at applyExtends (/home/user/.config/yarn/global/node_modules/eslint/lib/config/config-file.js:405:28) at loadFromDisk (/home/user/.config/yarn/global/node_modules/eslint/lib/config/config-file.js:556:22) at Object.load (/home/user/.config/yarn/global/node_modules/eslint/lib/config/config-file.js:592:20) at Config.getLocalConfigHierarchy (/home/user/.config/yarn/global/node_modules/eslint/lib/config.js:228:44) at Config.getConfigHierarchy (/home/user/.config/yarn/global/node_modules/eslint/lib/config.js:182:43)

I did add yarn global add babel-eslint eslint-plugin-react eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-flowtype. but i think this is not necessary anymore!

like image 590
Valking Avatar asked Jun 28 '17 10:06

Valking


People also ask

How install ESLint config react app?

Linting a React App In our terminal again, we need to npm install -g eslint-plugin-react . Alternatively if you're running ESLint locally, we run npm install eslint-plugin-react --save-dev . This will install the plugin we need, but we need to tell ESLint that we want this plugin to help us out.

What ESLint config does create react app use?

Because Create React App comes with ESLint already integrated. They use their own sharable ESLint configuration and this can be found under the eslintConfig object in package. json .

How do I uninstall ESLint config react app?

Basically, just delete . eslintrc and any other eslint config files(if any) from the project. Also, check your package. json and delete all eslint packages and do npm install on your project.


2 Answers

I think if you add the module mentioned in the error message (eslint-config-react-app) it should work? eg. yarn add --dev eslint-config-react-app

like image 142
iainbeeston Avatar answered Sep 22 '22 23:09

iainbeeston


There's probably a misconfiguration in your package-lock.json file, where ESLint was removed. I've encountered the exact same issue and solved it via:

  1. cd <your-project-directory>
  2. rm package-lock.json
  3. rm -rf node_modules
  4. npm install

You can run npm ls eslint --depth=99 to verify the eslint package is installed. I've stumbled upon this via a comment from feross on GitHub.

like image 33
ndequeker Avatar answered Sep 20 '22 23:09

ndequeker