complete-intro-to-react: Cannot find module 'eslint-config-prettier/react'

When using $ eslint **/*.{js,jsx} --quiet I get the following error:

image

and here is my .eslintrc.json `{ “extends”:[ “airbnb”, “prettier”, “prettier/react” ], “plugins”:[ “prettier” ], “parserOptions”:{ “ecmaVersion”:2016, “sourceType”:“module”, “ecmaFeatures”: { “jsx”:true } }, “env”:{ “es6”:true, “browser”:true, “node”:true } }

Any ideas what I am doing wrong?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 24

Most upvoted comments

This can happen when you are missing peer dependency.

yarn add --dev eslint-config-prettier

I had to use locally installed eslint to fix this error so when I reference local copy of eslint it works fine: ./node_modules/.bin/eslint **/*.{js,jsx} --quiet similar issue: https://github.com/eslint/eslint/issues/1238

Running it locally seemed to work for me. Adding "lint": eslint **/*.{js,jsx} to my packages.json, then running yarn link worked for me. My guess is when you use eslint in the command line, it’s looking at your global packages and not your local. When running yarn lint, it’s looking at your local packages.

For me yarn eslint **/*.{js,jsx} --quiet worked

@Ciwan1859 Wonder if you’ve found a better solution to this yet, by chance.

@f00z 's line./node_modules/.bin/eslint **/*.{js,jsx} --quiet is the only line that works for me.

I could not get the script command working for the life of me, but I WAS able to get the command line call of

>eslint js/ClientApp.js

and (testing with only one other fake file at this time)

>eslint */*.{js, jsx}

too (which gave me results without err for both files)

AFTER I globally installed

yarn global add eslint-config-with-prettier

Still scratching my head about why it won’t work from a script but onto other things

What actually end up solving the problem for me.

  1. Installed all eslint and prettier files as local dependencies yarn add -D eslint eslint-plugin-prettier prettier eslint-config-prettier
  2. Create a script inside my package.json for eslint :
...omitted_code

    "format": "prettier --write --single-quote --print-width=120 --parser=flow --tab-width=2 \"js/**/*.{js,jsx}\"",
    "lint": "eslint \"**/*.{js,jsx}\" --quiet"

...omitted_code
  1. yarn run lint should give you the desire output : ✖ 2 problems (2 errors, 0 warnings) if you are watching the Eslint Lecture

For future readers, I had the same problem and @joshuabahr puts me in track.

The eslint-plugin-react must be installed globally if the eslint is already installed globally, as documented here : https://github.com/yannickcr/eslint-plugin-react#installation

So i suggest to install the 2 npm locally, that seems a more clean approach.

npm install --save-dev eslint npm install --save-dev eslint-plugin-react

First run $ sudo yarn global add eslint-config-with-prettier I had to use sudo and then I tried with double quotes and it worked for me. I did: eslint "**/*.{js,jsx}" --quiet instead of eslint **/*.{js,jsx} --quiet

I’ve gotten the exact same error as mdmaroof, can’t find “node_modules/asn1.js”

Actually just found a solution, I believe. I had installed locally a more current version of ESlint. Run yarn add --dev eslint@3.19.0, it is the version being used in the course.

However, like others, I have to point to the local version of eslint (./node_modules/.bin/eslint) or else it will not run. If I try to run using globally installed eslint, it continues to say cannot find module eslint-config-prettier/react. Trying to perform a global install of the module gives me an error.

It looks like his completed branch is different than if you are following along, changing .eslintrc.json to this fixed it for me. { "extends": [ "plugin:flowtype/recommended", "airbnb", "prettier", "prettier/react" ], "plugins": ["flowtype", "prettier"], "parser": "babel-eslint", "parserOptions": { "ecmaVersion": 2016, "sourceType": "module", "ecmaFeatures": { "jsx": true } }, "env": { "es6": true, "jest": true, "browser": true, "node": true }, "globals": { "DEBUG": false } }

@Ciwan1859 @Beauvelop Have you tried adding in "eslint-loader": "1.7.1" Brian mentions in the videos that adding this solves the problem

yarn install prettier (or) nom install prettier instead of doing global install. make sure eslint and prettier are present in local node_modules folder