ESLint not working in VS Code?
If ESLint is running in the terminal but not inside VSCode, it is probably
because the extension is unable to detect both the local and the global
node_modules
folders.
To verify, press Ctrl+Shift+U in VSCode to open
the Output
panel after opening a JavaScript file with a known eslint
issue.
If it shows Failed to load the ESLint library for the document {documentName}.js
-or- if the Problems
tab shows an error or a warning that
refers to eslint
, then VSCode is having a problem trying to detect the path.
If yes, then set it manually by configuring the eslint.nodePath
in the VSCode
settings (settings.json
). Give it the full path (for example, like
"eslint.nodePath": "C:\\Program Files\\nodejs",
) -- using environment variables
is currently not supported.
This option has been documented at the ESLint extension page.
In my case, since I was using TypeScript with React, the fix was simply to tell ESLint to also validate these files. This needs to go in your user settings:
"eslint.validate": [ "javascript", "javascriptreact", "html", "typescriptreact" ],
configuring working directories solved it for me, since I had multiple projects with own .eslintrc
files openend in the same window.
Put this in your .vscode/settings.json
"eslint.workingDirectories": [
"./backend",
"./frontend"
],
thanks to this guy on github: https://github.com/microsoft/vscode-eslint/issues/696#issuecomment-542592372
PS: useful command to list all subdirectories containing an .eslintrc
except /node_modules:
find . .eslintrc | grep .eslintrc | grep -v node_modules
There are a few reasons that ESLint may not be giving you feedback. ESLint is going to look for your configuration file first in your project and if it can't find a .eslintrc.json there it will look for a global configuration. Personally, I only install ESLint in each project and create a configuration based off of each project.
The second reason why you aren't getting feedback is that to get the feedback you have to define your linting rules in the .eslintrc.json. If there are no rules there, or you have no plugins installed then you have to define them.
Case 1/2: First-time plugin installation? approval is necessary
Little "weird" user experience (Hard to notice) - anyway - Since V 2.1.10 -
You must change the "currently block" status bar on New/First installation.
ESLint plugin Version 2.1.10
changelog (08/10/2020)
no modal dialog is shown when the ESLint extension tries to load an ESLint library for the first time and an approval is necessary. Instead the ESLint status bar item changes to ESLint status icon indicating that the execution is currently block.
Click on the status-bar
(Right-Bottom corner):
Opens this popup:
Approve ==> Allows Everywhere
-or- by commands:
ctrl + Shift + p -- ESLint: Manage Library Execution
Read more here under "Release Notes":
https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint
Case 2/2: The plugin already installed/approve
Open the terminal Ctrl+`
Under output ESLint
dropdown, you find useful debugging data (Errors, warnings, info).
For example, missing .eslintrc-.json
throw this error:
Error: ENOENT: no such file or directory, realpath
Next, check if the plugin enabled:
By deafult there is no need to edit eslint.probe
Last, Since v 2.0.4 - eslint.validate
in "normal cases" (react, vue, typescript, js, html, md) not necessary anymore (old legacy setting)**
**Many out-of-date stackoverflow answers (even her) indicate that eslint.probe
file should be edited.
eslint.probe
= an array for language identifiers for which the ESLint extension should be activated and should try to validate the file. If validation fails for probed languages the extension says silent. Defaults to [javascript
,javascriptreact
,typescript
,typescriptreact
,html
,vue
,markdown
].