198

ESLint is not working for me in VS Code. I have the plugin installed in VS Code, and ESLint itself as a developer dependency in my package.json, which I have installed as well.

I modified the following option in the VS Code User Settings:

{
  "eslint.options": { "configFile": "C:/mypath" }
}

I have use the command eslint --init to add the basic .eslintrc.json to the main directory of my package.

Other people were able to get ESLint feedback from VS Code using the exact same package with the exact same ESLint config file.

I have received no feedback of any kind when directly breaking multiple rules that were all included in the recommended rule set that is by default inside of the .eslintrc.json file.

What am I missing?

Edit: I have tested using ESLint via command line, and everything worked as expected, with the errors found where they should have, however, these same errors never showed up in VS Code. The issue seems to be on VS Code's side and not ESLint.

John Landon
  • 2,121
  • 2
  • 12
  • 11
  • 11
    Note that, If you have installed **ESLint** successfully, but got no feedback from ESLint as you expected, then there's a chance that you might have forgotten to **initialize ESLint**. To do that, run this command from the root of your project `./node_modules/.bin/eslint --init` –  Mar 25 '20 at 10:58
  • I had already seen in the terminal `TypeError: Could not find the rule "canonical/filename-match-exported".`, but I'd ignored it. But I now think VSC was aborting there and not bothering to run any more rules. Once I removed `/* eslint-disable canonical/filename-match-exported */` from the files that had those comments, VSC started honoring my ESLint rules (even in tsx files). – Ryan May 26 '23 at 21:45

35 Answers35

130

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.

ParaBolt
  • 1,593
  • 2
  • 10
  • 16
  • thank you, spent a few hours figuring out why eslint did now work globally with vscode – Andrei Voicu May 26 '18 at 22:30
  • I had the same issue. This helped me to resolve it but I didn't need to change the settings.json file. I went into the `Problems` tab and clicked on the light bulb beside the error and on the pop-up window selected allow. – bshek Dec 09 '20 at 14:32
  • Honestly I was having the same issue, so restarted + updated VSCode and it just works now. – mstephen19 Jan 11 '23 at 17:32
  • Thanks a lot! Found my problem `- Unknown options: requireConfigFile` – Sergiy Ostrovsky Jan 21 '23 at 14:28
116

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" ],
Simone
  • 20,302
  • 14
  • 79
  • 103
66

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

Karl Adler
  • 15,780
  • 10
  • 70
  • 88
  • 1
    NOTE: On Windows 10, .vscode/settings.json in the root of our project were not taking effect, but they WERE for our Ubuntu WSL environments. On Windows 10, the default settings.json was under our %appdata% folder, and when we modified it to have the "editor.codeActionsOnSave ...." lines, it started working. The easiest way to get to the right settings.json is to go to the ESLint plugin settings and scroll to the bottom to find a link to it. So again, on Windows 10 only, it was ignoring the settings.json in our .vscode folder in the root of our project. – alfreema Aug 12 '21 at 20:36
52

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 enter image description here 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): enter image description here

Opens this popup:

enter image description here

Approve ==> Allows Everywhere

enter image description here

-or- by commands:

ctrl + Shift + p -- ESLint: Manage Library Execution

enter image description here

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).

enter image description here

For example, missing .eslintrc-.json throw this error: enter image description here

Error: ENOENT: no such file or directory, realpath

Next, check if the plugin enabled: enter image description here

By default 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].

jerone
  • 16,206
  • 4
  • 39
  • 57
Ezra Siton
  • 6,887
  • 2
  • 25
  • 37
  • 3
    I think this one needs to be pinned - that Allow action was so non-obvious. This fixed it all for me. – Chaos Crafter Apr 07 '21 at 01:47
  • You should [edit] your question so that it doesn't rely on images. Users with visual impairments, or users with images blocked, will not be able to make use of the information that's hidden in images. Pictures can sometimes add to an an answer, but should never be the sole source of any information. – miken32 Sep 13 '22 at 15:30
  • my status-bar does not have a eslint option – Waleed Ahmad Jun 13 '23 at 12:53
39

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.

EJ Mason
  • 2,000
  • 15
  • 15
  • 1
    If you have a local .eslintrc.json you do not need to define your configFile in your settings. – EJ Mason Jul 14 '17 at 02:26
  • 3
    I have the local `.eslintrc.json` already placed in the main folder of my project, and my rules extends the recommended rules by ESLint, which are the ones I was testing. I have also added some rules of my own to further test, but with no success. – John Landon Jul 14 '17 at 03:40
  • 74
    When using ESLint directly via command line, everything works properly, and it finds all errors. The issue here seems to be with VS Code, and not ESLint. – John Landon Jul 14 '17 at 03:41
  • 4
    try enabling eslint in your settings "eslint.enable": true. Make sure you don't have any eslint installed globally. and try to remove the configFile path. That is how I have my vscode set up. I run into a lot of problems when I have eslint globally and locally installed. – EJ Mason Jul 14 '17 at 03:46
  • I already have it set to true, and I just tried uninstalling it globally, to only have it locally and I have removed the path option with no success. – John Landon Jul 14 '17 at 14:17
  • Open up your output at the bottom of the screen. Change it to eslint up near the top right of the output window. Now what does it say in that window? – EJ Mason Jul 15 '17 at 00:15
  • I noticed that sometimes it takes a couple of minutes to activate the changes or even you need to restart vscode before something takes effect. For sure, you need to restart the program each time to see if new setting works or not – Roman Dec 06 '18 at 17:15
  • 7
    For me, the issue was that I had not installed ESLint extension in VSCode. – atulkhatri Apr 23 '19 at 11:47
  • I needed to create an `eslintrc.js` in the ROOT of my project (*i.e. not subfolders). – Nick Grealy Oct 01 '20 at 04:06
16

In my case, I had not installed the ESLint extension in VSCode, which was causing issue. Did it and it started working again.

atulkhatri
  • 10,896
  • 3
  • 53
  • 89
10

Since you are able to successfully lint via command line, the issue is most likely in the configuration of the ESLint plugin.

Assuming the extension is properly installed, check out all ESLint related config properties in both project (workspace) and user (global) defined settings.json.

There are a few things that could be misconfigured in your particular case; for me it was JavaScript disabled after working with TypeScript in another project and my global settings.json ended up looking following:

"eslint.validate": [
  { "language": "typescript", "autoFix": true }
 ]

From here it was a simple fix:

"eslint.validate": [
  { "language": "javascript", "autoFix": true },
  { "language": "typescript", "autoFix": true }
]

This is so common that someone wrote a straight forward blog post about ESLint not working in VS Code. I'd just add, check your global user settings.json before overriding the local workspace config.

dmudro
  • 2,894
  • 1
  • 21
  • 23
  • For me, in addition to what you've specified, I had to add `"javascriptreact"` and `"typescriptreact"` since my project uses React. – oyalhi Dec 13 '19 at 00:22
  • 1
    Great point. `javascript` and `javascriptreact` are [default values](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint#user-content-settings-options) but I think you would need to have `*scriptreact` added back for JSX files. – dmudro Dec 14 '19 at 08:27
10

I resolved the issue by restarting the ESLint Server. You can do this by opening up the Ctrl + P menu. Then you can enter > ESLint: Restart ESLint Server.

batatop
  • 979
  • 2
  • 14
  • 31
9

Restarting VSCode worked for me.

thedanotto
  • 6,895
  • 5
  • 45
  • 43
6

In my case ESLint was disabled in my workspace. I had to enable it in vscode extensions settings.

Melchia
  • 22,578
  • 22
  • 103
  • 117
6

In my case setting eslint validate to : "eslint.validate": [ "javascript", "javascriptreact", "html", "typescriptreact" ], did the job.

Tomasz Ostroga
  • 119
  • 1
  • 4
5

If you are using a global installation of ESLint, any plugins used in your configuration must also be installed globally. Like wise for local install. if u have installed locally and properly configured locally, yet eslint isn't working, try restarting your IDE. This just happened to me with VScode.

Onengiye Richard
  • 348
  • 6
  • 12
  • Ugh! I don't know why this didn't occur to me sooner. VSCode would not recognize module aliases defined in my Webpack config file and was displaying Eslint errors but running Eslint from the command line did not. Restarting VScode fixed the problem! – Jared Knipp Sep 13 '18 at 23:01
  • My problem was that I install eslint per-project (not globally) and I was using Docker, so I forgot to run `npm i` on my local machine. – Jami Feb 17 '22 at 17:19
5

In my case, I had to enable the ESLint "Always Show Status" setting in VSCode:

enter image description here

Then linting results started showing up immediately in VSCode.

java-addict301
  • 3,220
  • 2
  • 25
  • 37
4

I'm giving the response assuming that you have already defined rules in you local project root with .eslintrc and .eslintignore. After Installing VSCode Eslint Extension several configurations which need to do in settings.json for vscode

eslint.enable: true
eslint.nodePath: <directory where your extensions available>

Installing eslint local as a project dependency is the last ingredient for this to work. consider not to install eslint as global which could conflict with your local installed package.

LasithaMD
  • 115
  • 2
  • 11
4

I use Use Prettier Formatter and ESLint VS Code extension together for code linting and formating.

enter image description here

enter image description here

now install some packages using given command, if more packages required they will show with installation command as an error in the terminal for you, please install them also.

npm i eslint prettier eslint@^5.16.0 eslint-config-prettier eslint-plugin-prettier eslint-config-airbnb eslint-plugin-node eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-react eslint-plugin-react-hooks@^2.5.0 --save-dev

now create a new file name .prettierrc in your project home directory, using this file you can configure settings of the prettier extension, my settings are below:

{
  "singleQuote": true
}

now as for the ESlint you can configure it according to your requirement, I am advising you to go Eslint website see the rules (https://eslint.org/docs/rules/)

Now create a file name .eslintrc.json in your project home directory, using that file you can configure eslint, my configurations are below:

{
  "extends": ["airbnb", "prettier", "plugin:node/recommended"],
  "plugins": ["prettier"],
  "rules": {
    "prettier/prettier": "error",
    "spaced-comment": "off",
    "no-console": "warn",
    "consistent-return": "off",
    "func-names": "off",
    "object-shorthand": "off",
    "no-process-exit": "off",
    "no-param-reassign": "off",
    "no-return-await": "off",
    "no-underscore-dangle": "off",
    "class-methods-use-this": "off",
    "prefer-destructuring": ["error", { "object": true, "array": false }],
    "no-unused-vars": ["error", { "argsIgnorePattern": "req|res|next|val" }]
  }
}
Rafiq
  • 8,987
  • 4
  • 35
  • 35
3

I had similar problem on windows, however sometimes eslint worked (in vscode) sometimes not. Later I realized that it works fine after a while. It was related to this issue: eslint server takes ~3-5 minutes until available

Setting enviroment variable NO_UPDATE_NOTIFIER=1 solved the problem

Community
  • 1
  • 1
cimak
  • 1,765
  • 3
  • 15
  • 18
3

I had a similar problem with eslint saying it was '..not validating any files yet', but nothing was reported in the VS Code problems console. However after upgrading VS Code to the latest version (1.32.1) and restarting, eslint started working.

PRS
  • 741
  • 1
  • 7
  • 27
3

For me, i did accidentally disable ESLint when some prompt was shown by it.

Doing below steps fixed it for me

  1. Shift + Command + P and select ESLint: Disabled ESLint
  2. Close vscode
  3. Shift + Command + P and select ESLint: Show Output Channel
Abdul Vajid
  • 1,291
  • 1
  • 15
  • 25
2

If you are developing a project with eslint as an package.json dependency, make sure you run npm install. That fixed it for me.

JBaczuk
  • 13,886
  • 10
  • 58
  • 86
2

After installing the Eslint npm package and/or VS Code Extension by Dirk baeumer, Create .eslintrc.js configuration file as per your coding conventions.

Then, Enable all ESLint configurations in VSCode settings as follows:

  • Pressing shortcut key Ctrl + or Command + based on your OS OR search "Settings"
  • Type @ext:dbaeumer.vscode-eslint in your Search bar
  • Tick mark the following checkboxes
    • Eslint: Debug
    • Eslint: Enable
    • Eslint: Format Enable
    • Eslint: Lint Task Enable

Happy Linting

  • It's working for us on multiple computers and environments (Windows, Ubuntu WSL 1, Ubuntu WSL 2), and none of those need to be checked. We don't have a "Eslint: Enable" option. – alfreema Aug 12 '21 at 20:24
2

The .eslintrc.js file had a typo . More specifically I tried to add a rule in a wrong way . Once I removed the falsey rule everything was working fine immediately .

Cap Barracudas
  • 2,347
  • 4
  • 23
  • 54
1

In my case, it wasn't working because I had added only one folder of the monorepo to the project, even though I had the package.json and the extension configured. I worked only when I added the whole project (which contained the package.json file) to the VS Code.

shivangg
  • 521
  • 8
  • 15
1

Windows user here.

Tried everything, nothing worked. Finally removing the folder with eslint in .vscode/extensions and reinstalling fixed!

C:\Users<user>.vscode\extensions

Manoj Singh
  • 1,911
  • 1
  • 20
  • 22
0

Go to your settings.json file, add the following and, fix the eslint.nodepath. Tailor it to your own preferences.

 // PERSONAL
  "editor.codeActionsOnSaveTimeout": 2000,
  "editor.codeActionsOnSave": {
    "source.fixAll": true
  },
  "editor.fontSize": 16,
  "editor.formatOnSave": true,
  "explorer.confirmDragAndDrop": true,
  "editor.tabSize": 2,
  "eslint.codeAction.showDocumentation": {
    "enable": true
  },
  "eslint.nodePath": "C:\\{path}",
  "eslint.workingDirectories": ["./backend", "./frontend"],
Dharman
  • 30,962
  • 25
  • 85
  • 135
DJN
  • 153
  • 2
  • 10
0

In my case, I had the .eslintrc.json file inside the .vscode folder. Once I moved it out to the root folder, ESLint started working correctly.

Dino Bansigan
  • 109
  • 2
  • 4
0

You can open problem tab to check there is an ESLint permission request or not. If you see it, try to click the lightbulb and fix the issue, it works for me.

problem tab in vscode terminal window

wish you luck!

BaalWu
  • 21
  • 2
0

If you are using Yarn version 2, it might be the culprit. For me, once I ran yarn set version classic and yarn install everything started working again.

JoshJoe
  • 1,482
  • 2
  • 17
  • 35
0

I had the same issue. ESLint extension was enabled and .eslintrc file had some rules but VS Code did not show any autofix for my code.

The problem was in my folder structure, it was something like that

-workspace-folder
  -client
    -node_modules
    -src
    -.eslintrc.json
    -package.json
    -...other files

After changing folder structure to the like below example, with the delete package-lock.json and reinstallation of all deps, VS code began to show es lint errors.

-workspace-folder
   -node_modules
   -src
   -.eslintrc.json
   -package.json
   -...other files
Maksim
  • 31
  • 5
  • If you have the same problem, doesn't give an answer for telling it. It's better to upvote the question and/or give a comment for put some additional data. – Sakura Kinomoto Jun 26 '21 at 23:20
0

I get the same problem of eslint not working. When adding these extensions in .eslintrc.json file, it works fine for me :

"extends": [
        "plugin:@angular-eslint/recommended",
        "plugin:@angular-eslint/template/process-inline-templates",
        "eslint:recommended",
        "plugin:@typescript-eslint/recommended"
      ],
Sihem Hcine
  • 1,089
  • 5
  • 24
  • 40
0

In my case, I followed https://eslint.org/docs/user-guide/getting-started#installation-and-usage to setup the es-lint. But after the installation it's wasn't working.

Fix: But just restarting the vs-code solved the problem for me.

Ram
  • 113
  • 1
  • 6
0

In my case ESLint was properly installed and enabled and working in another workspace with identical settings.

What helped was to disable the extension in the workspace where it was not working, reload VSCode and then enable the extension back. Then it immediately started working.

Asu
  • 1,723
  • 2
  • 21
  • 32
0

For me, the latest version of eslint does not work correctly with Visual Studio code in all my packages, so I had to install an earlier global version:

npm i -g eslint@7.32.0

J

Jonathan
  • 3,893
  • 5
  • 46
  • 77
0

For me, it was a problem with using nvm to install node.

In a terminal, run npm root -g to get the global node_modules install folder. It should look something like /Users/{username}/.nvm/versions/node/v16.12.0/lib/node_modules (for mac).

Then, in the settings for ESLint, edit the Node Path to point to this node_modules location.

0

I had .eslintignore defined and it referred to a subfolder that I was checking.

When I ran command line, eslint let me know that .eslintignore was blocking the analysis of my file. In vscode no such message.

So double check your .eslintignore file.

BruceJo
  • 591
  • 6
  • 17
0

Simple Solution (not best): Add an empty eslint.options to setting.json; this has worked for me:

"eslint.options": {}
desertnaut
  • 57,590
  • 26
  • 140
  • 166