ESLint not working in VS Code?
If ESLint is running in the terminal but not inside VSCode, it is probablybecause the extension is unable to detect both the local and the globalnode_modules
folders.
To verify, press Ctrl+Shift+U in VSCode to openthe 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 thatrefers 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 VSCodesettings (settings.json
). Give it the full path (for example, like"eslint.nodePath": "C:\\Program Files\\nodejs",
) -- using environment variablesis 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