Vscode-eslint: "Failed to load eslint library" when installed

Created on 27 Jan 2016  路  20Comments  路  Source: microsoft/vscode-eslint

Currently getting the error message: "Failed to load eslint library. Please install eslint in your workspace folder using 'npm install eslint' or globally using 'npm install -g eslint' and then press Retry."

I'm currently using:
Code Version 0.10.6 (0.10.6),
eslint extension 0.10.11,
Node version 4.2.6
eslint version 1.10.3

I've installed eslint globally and can even run it via gulp. The plugin was working for me up until recently, no clue as to what exactly changed.

needs more info

Most helpful comment

This should also have in mind that you could have eslint installed globally with yarn, not only on NPM... that's my case. EsLint works but the message shows as if eslint is not there and it's actually working

All 20 comments

+1 for me. First timer, so I didn't know it was a "new problem"

+1

It looks like the recent change to this lines up with the timing that I started seeing the error message:
https://github.com/Microsoft/vscode-eslint/commit/34bbbf55cd9befbfec1e9fb625d3561eecbc89f4#diff-53a5a7cf3508861eefb1979db3e79299R14

I was not able to reproduce this. I can successfully load the eslint library from an node_module installed into the workspace folder or globally.

@adamweeks any additional data on how to reproduce. The commit you pointed to can't be the issue since I didn't publish a new version of the eslint plugin. In addition the commit didn't change any code that is responsible for loading the eslint code. What version of eslint do you have installed globally ?

@dbaeumer Sorry, I was just reaching to try to figure out what caused it to stop working.

My global eslint is 1.10.3.

Running from the workspace directory:

which eslint
/usr/local/bin/eslint
eslint -v
v1.10.3

I've also run npm install eslint in the workspace, but which still picks up from the global path.

+1

Ubunutu 14.04 LTS
Code Version 0.10.6
Nodejs 5.4 (via nvm)
installed eslint eslint 1.10.3 globally (and later also in workspace)
installed eslint extension 0.10.11
... getting the error message no matter what i try

I've found a workaround for the problem, but not a real solution as to what was happening. By simply deleting the VS Code app and reinstalling it, the eslint plugin started working again.

@adamweeks this sounds very wired and I don't have an explanation for it. One question: do you have a NODE_PATH environment variable. I fixed a bug which resulted in module load failures in case there was a NODE_PATH environment present in the system.

@dbaeumer so after a reboot the issue has come back up. I do not have a NODE_PATH environment variable but it does appear like I have something in common with @geroyche. We're both using nvm. I tried installing the plugin on a machine without nvm and it worked fine. There might be an issue with using this plugin along side of nvm.

@adamweeks to my knowledge npm tweaks the NODE_PATH variable which causes problems when I try to load the eslint plugin. For the whole discussion see https://github.com/Microsoft/vscode-eslint/issues/13. I will push a new version of the eslint plugin with the next VSCode release. This will contain the fix. If you want to see if this will help you can do the following:

  • go to the eslint extension installation (e.g. .vscode-insiders/extensions/dbaeumer.vscode-eslint-0.10.11 in your home directory)
  • go to server\node_modules\vscode-languageserver\lib
  • open the file files.js
  • change line 59 from
newEnv[nodePathKey] = newEnv[nodePathKey] + separator + nodePath.join(separator);

to

newEnv[nodePathKey] = nodePath.join(separator) + separator + newEnv[nodePathKey];

Let me know if it helps.

TL;DR:

Remove old node_modules folder from home directory

@dbaeumer that fix did not help me out so I went off to do a little investigation.

I changed line 77 in files.js to e(toRequire) and also modified line 50 of server.js to:
`return Promise.reject(new vscode_languageserver_1.ResponseError(99, 'Error: ' + error, { retry: true }));

It told me that it was using eslint from ~/node_modules.

Running which eslint pointed me to /usr/local/bin/eslint and it reported version 2.1.0.

When I looked in ~/node_modules/eslint, it was reporting 1.0! I'm not sure what was using the node_modules in the home directory, but I've deleted it, restarted code and we are linting again!

I don't know if my setup will fix anyone else's issues, but it is worth a shot. Thanks again @dbaeumer!

@adamweeks that is interesting. At the end I can't fully control from where node is loading the code since it doesn depend on the environement. What I will do is to add some information in the UI to show from where the the eslint plugin loaded the eslint module so that users can track this down better

I also received this error and recently updated from NPM v2 to v3 which uses a different folder structure for dependencies. Suspecting this might be an issue, I removed ALL globally installed packages and re-installed them. This seems to have fixed my issue.

The loading code has changed quite a bit since March 2016. I will close the issue. Please ping if one still sees the issue.

This affects me with VS.Code 1.12.1 f6868fc Ubuntu 17.04

I have node setup so that global modules end up in ~/.node and that is added to NODE_PATH in my .zshrc file. But ok, I understand that VS Code does not inherit my shell environment, which is why I added "eslint.nodePath": "/home/bmarkovic/.node" to my user settings JSON file. I still get this error tho.

Also it would be very helpfull if the output did contain info where from the plugin is attempting to load the module which would help us hunt it down.

You can enable tracing support by adding to your workspace settings "eslint.trace.server": "messages". This should print more to the output channel.

@bmarkovic if you want to load global npm modules from a different location did you tweak the npm get config prefix setting. This should point to the gobal npm location and is respected by the ESLint extension.

Thanks @dbaeumer. I encountered this issue in my VSCode+eslint setup. Great pointer in your comment above. I enabled tracing support by adding "eslint.trace.server": "messages" in my settings; and noticed that "eslint.nodePath" was pointing to the wrong directory, instead of where npm global packages are installed. So, correcting that fixed it. The plugin is now loading the eslint library successfully. And linting is working!

@dbaeumer Sorry I've missed this reply. You probably meant npm config get prefix and yes it was set, but it was only when I made sure that in global npm config (the globalconfig entries when you get when you do npm config list) the prefix is set to the same location that it finally worked.

So setting it only in local npm config (~/.npmrc in my case) doesn't cut it. Hope someone else finds this useful.

Another tip to whoever reads this later, when I was toying with this I noticed that changes in npm config were only picked up when fully restarting VS Code (as opposed to reloading the window).

@bmarkovic correct it is npm config get prefix

This should also have in mind that you could have eslint installed globally with yarn, not only on NPM... that's my case. EsLint works but the message shows as if eslint is not there and it's actually working

Was this page helpful?
0 / 5 - 0 ratings