create-react-app: Failed to load plugin '@typescript-eslint' declared in '.eslintrc » eslint-config-react-app#overrides[0]': Cannot find module 'typescript'
Describe the bug
When I run eslint: lint whole folder
task, it fails because of the error mentioned in the title.
Did you try recovering your dependencies?
Yes, I did.
Which terms did you search for in User Guide?
The issue is not related to any of them, it’s ESLint.
Environment
Environment Info:
current version of create-react-app: 3.4.1
running from C:\Users\X\AppData\Roaming\npm\node_modules\create-react-app
System:
OS: Windows 10 10.0.18363
CPU: (8) x64 Intel(R) Core(TM) i7-2670QM CPU @ 2.20GHz
Binaries:
Node: 12.10.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.4 - C:\Users\X\AppData\Roaming\npm\yarn.CMD
npm: 6.14.4 - C:\Users\X\AppData\Roaming\npm\npm.CMD
Browsers:
Edge: 44.18362.449.0
Internet Explorer: Not Found
npmPackages:
react: ^16.13.1 => 16.13.1
react-dom: ^16.13.1 => 16.13.1
react-scripts: ^3.4.1 => 3.4.1
npmGlobalPackages:
create-react-app: Not Found
Steps to reproduce
Just run eslint: lint whole folder
task.
This is my ESLint config:
{
"extends": [
"react-app",
"airbnb",
"prettier"
],
"env": {
"mocha": true,
"es6": true,
"commonjs": true,
"browser": true
},
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true,
"modules": true,
"experimentalObjectRestSpread": true
}
},
"plugins": [
"prettier"
],
"rules": {
"no-underscore-dangle": "off",
"class-methods-use-this": "off",
"import/no-extraneous-dependencies": [
"error",
{
"devDependencies": true
}
]
}
}
Expected behavior
It should not throw exceptions.
Actual behavior
It throws the above exception.
Reproducible demo
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 76
- Comments: 65 (1 by maintainers)
Commits related to this issue
- CONFIG complete eslint setup * integrate prettier * add rules of hooks * ignore node_modules to fix https://github.com/facebook/create-react-app/issues/8936 * fix linting errors in serviceWorker.js — committed to bargar/create-react-app-starter by bargar 4 years ago
- Build: add .eslintignore to stop linting node_modules Lint action was trying to lint our node_modules, which contain some .ts files. To fix the issue, we add /node_modules to .eslintignore. Solution... — committed to the-sol/pomodoro by Amna-Qassim 3 years ago
- Fixes reported issue with create react app when running eslint See on https://github.com/facebook/create-react-app/issues/8936 — committed to mbustosp/challenge-t9_emulator by mbustosp 3 years ago
- Feature/frontend scaffolding (#1) * Adds react base app * Adds prettier and extends eslint rules with airbnb's ones * Fixes reported issue with create react app when running eslint See on https://... — committed to mbustosp/challenge-t9_emulator by mbustosp 3 years ago
- Release 1.0 (#15) * Feature/frontend scaffolding (#1) * Adds react base app * Adds prettier and extends eslint rules with airbnb's ones * Fixes reported issue with create react app when running ... — committed to mbustosp/challenge-t9_emulator by mbustosp 3 years ago
- Add `node_modules` to `.eslintignore` Related https://github.com/facebook/create-react-app/issues/8936\#issuecomment-653862274 — committed to dooboolab/homepage by hyochan 2 years ago
- Fix iOS and android build (#25) Update packages Add `node_modules` to `.eslintignore` - Related https://github.com/facebook/create-react-app/issues/8936\#issuecomment-653862274 Fix iOS build ... — committed to dooboolab/homepage by hyochan 2 years ago
The issue can be resolved by using a
.eslintignore
file. In my case is seems eslint was trying to lint thenode_modules
and adding a eslintignore file with just node_modules in it stop the error.Well the only thing that helped me is
npm install --save typescript
. It’s bad, but however it resolves the problem.@Vanuan thank you, it fixed my problem!
So I changed my script from
eslint .
toestlint ./src
and it now works like a charm. So I guess it was finding some *.ts file in any of the node modules or any other hidden folder that might have a ts file.I run
npm install @typescript-eslint/eslint-plugin@latest --save-dev
. Maybe is not the right thing to do but it workedmake sure your node version is not 12.x . i used a higher version with nvm and it is resolved. (16.14.0)
I was having the same issue, but after create a .eslintignore file and add node_modules, everything goes well, hope it helps
I don’t use vs code or .ts files - there is an issue with create-react app
I spent 4 hours to find this solution. And it seams that error "Failed to load plugin ‘@typescript-eslint’ declared in '.eslintrc " does not describe what’s actually going on. PS. Sorry for my English)
Why does this happen? Because, although ESLint does indeed ignore
node_modules/
by default, the override does not in terms of deciding whether the TypeScript plugins should be loaded (which is why you seeeslint-config-react-app#overrides[0]
in the error).The override is provided so that, if there is any TypeScript in your project, those rules are automatically applied. However, as the override is enabled by the presence of TypeScript files in
node_modules/
, it then tries to load those plugins. They require TypeScript, so you see TS-related failures even though you have no TS in your own code.How do I fix it? There are a couple of options, which have been outlined on this SO question, broadly:
Install TypeScript anyway. This will allow the plugins to load, although they won’t actually get used. This works fine but adds complexity (and surface area for vulnerabilities) to your dependencies.
Explicitly ignore
node_modules/
. You can do using any of the configuration options ESLint offers. The simplest is probably to havenode_modules/
listed in a root.eslintignore
, but there are a couple of others.How will it get fixed upstream? I opened #9310 to fix this, applying the latter solution; looks like it’s currently scheduled for the 4.1 milestone.
Did you try “npm i -D typescript” in your project dir?
Here’s the config that triggers the error:
https://github.com/facebook/create-react-app/blob/f5c3bdb65480f93b2d4a4c2f3214fc50753de434/packages/eslint-config-react-app/index.js#L57-L69
Apparently,
*.ts
files are being compiled even if you specifyjs
glob pattern:eslint './src/**/*.{js,jsx}'
. Maybe it’s a bug in the eslint plugin loading mechanismIn my case it was an issue with using
yarn
andnpm
. No I am not using them together, I always useyarn
but this particular project was usingnpm
and by muscle memory I added a package withyarn add <package>
but stopped it mid way.Then I installed it using
npm i <package>
and issue started happening. Can’t guarantee 100% this was the cause, but the timing of stuff made me think that. 🤷♂️My solution was deleting node_modules and install again using
npm
.Ran in to this issue with a repo on two different dev machines. Issue was node version. The repo was built for node 16, the machine running node 12 threw this error. Hope this helps someone in the future 👍
I’m facing the same problem. Using Visual code v1.46.
There is no error on my local (i.e. Visual Code) but on the quality gate in the CI/CD pipeline of Gitlab.
Can somebody please help
Using:
"lint": "eslint --ignore-path .gitignore .",
also works.
https://eslint.org/docs/user-guide/configuring/ignoring-code#using-an-alternate-file
This comment seems correct, and this is one example of working around it for now: https://github.com/facebook/create-react-app/issues/8936#issuecomment-674060591
npm install
resolve the issue for meI thought
node_modules
would be ignored because I read this in eslint’s user guide:There are some exceptions to this documented in the user guide but I don’t think they apply to my case. Maybe I hit an undocumented exception because I was using
./node_modules/.bin/eslint
. In any case, using.eslintignore
orignorePatterns
in the.eslintrc
file resolves the issue I had.@Lelith so the command you’re running is
eslint .
. The dot means “current working directory”. Which means it would lint all the files, even those you don’t consider to be a part of your project.Try to limit the scope of your lint command by changing it to the folder you want to lint, e.g.
eslint ./folder
. Or remove all the*.ts
you can find in your project directory.My problem was solved with next workaround:
npm install -D eslint@7.32.0
https://github.com/eslint/eslint/issues/15149#issuecomment-939501275@nagarciah works for me, Thanks!
@iansu Yes, it is an issue when I run
eslint .
but when I created a.eslintignore
file withnode_modules/
, it vanished. No need to install typescript into project.@Vanuan i was following this article to set it up: https://medium.com/@pppped/extend-create-react-app-with-airbnbs-eslint-config-prettier-flow-and-react-testing-library-96627e9a9672
and the react script used is:
"lint": "eslint ."
as additional node - i started a fresh project based on the create-react-app template redux
here is my package.json
i use VSCode but i tried executing the command also from my normal terminal, where it fails with the same error message. The VSCode linter per file works without throwing exceptions.
also did just run into it, i am not using typescript in my project. here is my eslint config
And need to change path of ESLint package. Settings -> Language & Frameworks -> JavaScript -> Code Quality Tools ->EsLint.
Check field ‘Manual ESLint configuration’ -> ESLint package. It was “…/current project/node_modules/eslint” and I change path to “C:\Program Files\nodejs\node_modules\eslint” and it’s work for me)
p.s. Configuration File -> Automatic search
@tonykaram1993 this was the only solution in the thread that worked for me! Thanks!
@textbook thank you for clarifying it. But I did downgrade to
7.32.0
and everything works again…@alvipeo it’s a problem with the configuration in CRA, not ESLint itself. Changing ESLint version won’t make any difference, this is scheduled for a fix in CRA 4.1.
This error happens to me because i wasn’t installed typescript locally. I thought that this was not required, i’m working on a node.js project
@Kicu The plugin determines whether you’re using Typescript or not by searching for *.ts files. You think you’re not using ts while in fact you are.
You can either continue running eslint per file or remove the ts file eslint is trying to lint
@Lelith what’s the command you’re running?