Reputation: 96474
I am getting this error when i do eslint .
Error: Failed to load parser '@typescript-eslint/parser' declared in '.eslintrc.yml »
eslint-config-react-app#overrides[0]': Cannot find module 'typescript'
Upvotes: 2
Views: 4263
Reputation: 121987
Because there are TypeScript files - although ESLint excludes node_modules/
from linting by default, CRA's override (in order to load appropriate plugins for any TypeScript files, this is why you see eslint-config-react-app#overrides[0]
in the output) does include the content of node_modules/
(see e.g. this issue).
You can install TypeScript, but if you don't intend to use any TypeScript files in your own source you can be more specific about what you want to lint instead. Either:
Change the script in package.json
to only lint the source directory:
"lint": "eslint src/"
Create a .eslintignore
(or another file, if you set the right --ignore-path
) file containing:
node_modules/
Add to the ESLint configuration object in package.json
(or pass it as an --ignore-pattern
):
"eslintConfig": {
"extends": "react-app",
"ignorePatterns": [
"node_modules/"
]
}
The latter two options are from the documentation on configuration.
Upvotes: 5
Reputation: 96474
npm install --save-dev typescript
Then eslint .
will work as intended and can use the .eslintrc.yml
file.
btw I had also just installed
npm install -save-save eslint-plugin-typescript
in case you are doing this as you may need that too.
btw do NOT install eslint with npm install eslint... as it may mess up due to the fact that... crewate-react-app already has it (but a lower version). so just add your eslintrc.yml file and it will work (be applied in the editor, and with this fix, at the command line as neeeded).
example output:
.../src/components/SignUp/index.js
1:41 error Missing semicolon semi
7:26 error Unnecessary parentheses around expression no-extra-parens
15:2 error Missing semicolon semi
32:13 error 'username' is assigned a value but never used no-unused-vars
47:63 error Missing semicolon semi
95:26 error Unnecessary parentheses around expression no-extra-parens
Upvotes: 1