Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 pres #28

Closed
egamma opened this issue Feb 11, 2016 · 36 comments
Assignees
Labels
info-needed Issue requires more information from poster

Comments

@egamma
Copy link
Member

egamma commented Feb 11, 2016

From @Ciget on February 10, 2016 21:56

Hi folks,

I several time during using VS Code see error like this:

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 pres

Of course i`ve tried to install it locally and globally as well, but no result - still the same error.
My OS - Windows 10. Version of VS Code - 0.10.8

Does somebody has the same issue and maybe you have thoughts how to fix it?
Thanks.

Copied from original issue: microsoft/vscode#2909

@dbaeumer
Copy link
Member

Hmm. this works for me with a locally installed eslint and 0.10.8. See screen shot

capture

@Ciget do you have a NODE_PATH environment variable set. I fixed a bug lately which cause the eslint load fail in case a NODE_PATH environment variable is present.

@adamweeks
Copy link

@egamma are you using nvm? I'm experiencing this issue as well on my machines that have nvm installed.

@adamweeks
Copy link

Sorry, looks like the original issue author was @Ciget

@Ciget
Copy link

Ciget commented Feb 11, 2016

@dbaeumer, nop, even after remove this variable from env settings and restart - still have this issue.

@ShimShamSam
Copy link

As per my comment on issue #24, removing all globally installed NPM packages and reinstalling them fixed my issue. I'm pretty sure this is related to the latest NPM version using a different folder structure for dependencies, which I recently upgraded to.

@collinforrester
Copy link

@ShimShamSam Are you on windows? I just tried removing all of my global modules per your solution and it didn't work.

Very well could be because I'm on windows though and have my global modules stored in a non standard location.

@dbaeumer
Copy link
Member

I played a little with this and here are my finds:

  • using nvm together with the eslint extension worked for me.
  • a non standard global modules store worked for me as well

The eslint plugin uses 'npm config get prefix' to find the location of the globally installed modules. @collinforrester does this point to your global store ?

@dbaeumer dbaeumer added the info-needed Issue requires more information from poster label Apr 14, 2016
@collinforrester
Copy link

Yes it does.

I just tried to recreate the issue that I was having and its no longer occurring on this machine. So a combination of ShimShamSam's solution, reboot, vscode, and eslint update.. something seems to have fixed it.

I realize that doesn't help much as far as specifics, but its what worked for me.

@unional
Copy link

unional commented Apr 15, 2016

I have a different case but with the same error. By the way I tested my project that is using eslint is it is working for me (I installed it locally).

My case is when opening a project that does not have package.json, eslint not installed, and there are no.eslintrcor.eslintrc.*in the project. In this case thevscode-eslint` should not be activated.

@dbaeumer
Copy link
Member

@unional agree. Please see: #68

@GeorgeSapkin
Copy link

GeorgeSapkin commented May 23, 2016

The issue I had when installing ESLint in npm prefix is that the prefix was configured as an environment variable in .bashrc instead of using npm config set prefix. So npm config get prefix returned the correct path even though it was not in npm config get and VS Code couldn't find ESLint. After I removed environment variable and moved prefix to npm config, ESLint was found.

@dbaeumer
Copy link
Member

@GeorgeSapkin thanks for the insight. Didn't even know that this is possible.

@novembrea
Copy link

I have the same issue and unfortunately it didn't get resolved via aforementioned solutions. I'm using NVM and ESlint is installed globally. Here are the details:

  • OS: Ubuntu 16.04
  • VSCode: 1.2
  • Node: 6.2.1
  • NPM: 3.9.3
  • ESlint: 2.12.0
which node
>/home/nvma/.nvm/versions/node/v6.2.1/bin/node
which eslint
>/home/nvma/.nvm/versions/node/v6.2.1/bin/eslint
npm config get prefix
>/home/nvma/.nvm/versions/node/v6.2.1

I've tried to use it locally too, but to no avail. I'm out of options.

@dbaeumer
Copy link
Member

Actually, I don't understand why this is happening. I created #92 to add tracing options to better understand to which paths the module loading resolves and what exception occurred during module resolving.

@dbaeumer
Copy link
Member

@nvma quick question: how does the directory look like below >/home/nvma/.nvm/versions/node/v6.2.1

Can you let me know where exactly the eslint node module resides on disk in your setup.

@dbaeumer
Copy link
Member

@nvma and can you provide me with the output of npm root -g

@draptik
Copy link

draptik commented Jun 28, 2016

I am also running into the same issue.

$ npm root -g
/home/patrick/.nvm/versions/node/v6.2.2/lib/node_modules
$ which eslint
/home/patrick/.nvm/versions/node/v6.2.2/bin/eslint
$ which node
/home/patrick/.nvm/versions/node/v6.2.2/bin/node
$ la ~/.nvm/versions/node/v6.2.2/lib/node_modules/
drwxr-xr-x  7 patrick users 4,0K 28. Jun 21:38 eslint/
  • OS: Arch Linux (64)
  • VSCode: 1.2.1
  • Node: 6.2.2
  • NPM: 3.9.5
  • ESLint: 2.13.1

@dbaeumer
Copy link
Member

dbaeumer commented Jul 6, 2016

@draptik thanks. Could you also run 'npm config get prefix'. I have the felling global modules are resolved against the wrond directory when using nvm

@Nighthawk22
Copy link

Nighthawk22 commented Jul 13, 2016

@dbaeumer same problem here:

[:~] $ npm root -g
/Users/maxzollneritsch/.nvm/versions/node/v4.4.3/lib/node_modules
[:~] $ which eslint
/Users/maxzollneritsch/.nvm/versions/node/v4.4.3/bin/eslint
[:~] $ which node
/Users/maxzollneritsch/.nvm/versions/node/v4.4.3/bin/node
[:~] 127 $ ls -la  ~/.nvm/versions/node/v4.4.3/lib/node_modules/
total 0
drwxr-xr-x  10 maxzollneritsch  staff  340 13 Jul 10:09 .
drwxr-xr-x   4 maxzollneritsch  staff  136 12 Apr 21:32 ..
drwxr-xr-x  11 maxzollneritsch  staff  374 13 Jul 10:09 eslint
[:~] $ npm config get prefix
/Users/maxzollneritsch/.nvm/versions/node/v4.4.3
  • OS: OS X 10.11.5
  • VSCode: 1.3.1
  • Node: 4.4.3
  • NPM 3.10.5
  • ESLint: 3.0.1

Installing it locally on the root folder of the project works for me but for me its not really a nice way.

@dbaeumer
Copy link
Member

@Nighthawk22 this actually all looks ok. Can you do one thing for me: in /Users/maxzollneritsch/.nvm/versions/node/v4.4.3/lib/node_modules is there an eslint folder ?

@Nighthawk22
Copy link

@dbaeumer Is listed in my comment, yes there is one

@p3k
Copy link

p3k commented Jul 14, 2016

I have the same issue, using prefix = ${HOME}/.local/lib/npm in ~/.npmrc

→ npm config get prefix
~/.local/lib/npm

→ which eslint
~/.local/lib/npm/bin/eslint

→ ls -n ~/.local/lib/npm/bin/eslint
lrwxr-xr-x  1 501  109  40 Jul 14 13:44 ~/.local/lib/npm/bin/eslint -> ../lib/node_modules/eslint/bin/eslint.js

@madcampos
Copy link

I'm having this issue with a single file, a html opened from a folder with no eslint configuration file nor package.json, it's just that single file in the folder actually. And with a project that is configured, with package.json and .eslintrc.

I'm not using nvm and eslint is installed globally.
Here are the versions:

OS: Windows 10 build 14393
VS Code: 1.3.1
Node: 6.3
npm: 3.10.3
eslint: 3.1.1

Also, here are the npm commands:

madca@Freyr ~ $ npm root -g
C:\Users\madca\AppData\Roaming\npm\node_modules

madca@Freyr ~ $ npm config get prefix
C:\Users\madca\AppData\Roaming\npm

@wooramy
Copy link

wooramy commented Jul 28, 2016

I had an similar issue after uninstalling old node version and I was able to fix it by resetting nvm default to latest node version.

Here's what happened.

[Repro Steps]

  1. nvm default was set to node version 0.10.x
  2. Installed vscode and eslint extension (which worked fine)
  3. Installed node version 4.4.x (still fine)
  4. Uninstalled node version 0.10.x (broken)
  5. Okay, ran 'npm install -g eslint' for new node version 4.4.x (still broken)
  6. Ah ha. nvm 'default' was gone once I had uninstalled the old Node version
  7. nvm alias default 4.4
  8. Relaunch vscode

Tada!

@rickmed
Copy link

rickmed commented Jul 28, 2016

Mine works when the plugin uses the global eslint install but when I install eslint locally it does not work.

Using nvm
OS: Windows 10 x64
VS Code: 1.3.1
Node: 6.3
npm: 3.10
eslint: 3.1

@ctumolosus
Copy link

ctumolosus commented Aug 2, 2016

This happens to me when I open a single javascript file that is part of a project with ESLint installed locally. For example, I use iTerm and run my watch script, whenever an error is reported I use CMD+Click to quickly open a file.

Ideally, it should find the ESLint package in my project, but I was able to fix the problem by adding { "window.openFilesInNewWindow": false } to VSCode user settings.

@madcampos
Copy link

An update:
I ran into a similar issue (with nodemon not finding my script). It was caused by a custom script that runs on initialization for cmd.exe (configured via registry) that changes the working directory.
I removed the script, reopened vscode and esthe linting was working again.

@Beatusvir
Copy link

I've run into this several times, besides the obvious failed installs or things like that. I noticed VSCode will not detect eslint if you current folder is not the project root. I mean, if your current workspace folder has no node_modules folder in there, it fails. I have to open the root folder for it to be detected. I'm not sure if there is a way to go around this or if it's a different issue.

@vxzhong
Copy link

vxzhong commented Aug 24, 2016

"child_process.exec" use '/bin/sh' as the default shell, but I use 'zsh', so 'npm config get prefix' maybe failed because of the wrong shell.

@vxzhong
Copy link

vxzhong commented Aug 24, 2016

After chsh -s /bin/zsh, reboot the mac osx, then the vscode will detect the default shell to 'zsh', then the global installed 'eslint' will be found.

@dbaeumer
Copy link
Member

dbaeumer commented Aug 24, 2016

I re-implemented the eslint module resolution algorithm (see microsoft/vscode-languageserver-node#77, https://github.com/Microsoft/vscode-languageserver-node/blob/master/server/src/files.ts#L103).

The new approach loads eslint from parent folders so you don't need to open the project root anymore. In addition it does NOT rely on npm config get prefix nor npm root -g. And it doesn't mess with the NODE_PATH anymore. So as long as the shell variables travel to VS Code eslint package resolving should be fine now.

I did various tests and things look good to me. However I kept the old resolution in and it can be enabled via "eslint._legacyModuleResolve": true. I will close this issue and will publish a new version of ESLint with the next update of VS Code. If you still see issues then open a new issue here.

@FallenMax
Copy link

I still run into this issue. I'm using yarn and my global eslint has path: /usr/local/bin/eslint.
By reinstalling eslint using npm instead of yarn, the extension can now resolve eslint (at /usr/local/lib/node_modules/eslint/lib/api.js) and run without problem.

@dbaeumer
Copy link
Member

The ESLint extension has currently no support for globally install eslint module via yarn. I opened: #187

@BairDev
Copy link

BairDev commented Mar 14, 2017

@dbaeumer Should I comment this issue, if the problem has reoccurred? Or #92?

I still have this problem:

Failed to load the ESLint library for the document /home/path/to/my/file.js

To use ESLint in this workspace please install eslint using 'npm install eslint' or globally using 'npm install -g eslint'.
You need to reopen the workspace after installing eslint.

Some versions:

ESLint: 1.2.7
VSCode: 1.10.2
nvm: 0.33.1
node (current): 6.10.0
Linux Kernel: 4.8.0-41-generic

You've said, that ESLint does not use npm config get prefix or npm root -g anymore, but just in case you might need them:

npm config get prefix
-> # /home/myName/.nvm/versions/node/v6.10.0

npm root -g
-> # /home/myName/.nvm/versions/node/v6.10.0/lib/node_modules

ESLint has been installed In the last folder.

Finally there are some weird lines in my .bashrc:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm

Thanks!

@dbaeumer
Copy link
Member

@BairDev how did you install eslint globally. Using yarn?

I just checked and the ESLint extension works correctly if:

  • global module is install using npm
  • npm get config prefix returns the location where the global eslint is installed.

@BairDev
Copy link

BairDev commented Mar 28, 2017

@dbaeumer Sorry for kind of spamming this issue, but the problem has disappeared. I've just created a .eslintrc and then the stuff started to work. Thanks anyway.

But in order to answer your question: I've installed eslint via npm install -g, if I remember correctly. We have a quite complex project set-up, with using npm link and stuff like that, maybe this was the reason for the hiccup.

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 21, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests