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" ],