volta
volta copied to clipboard
vscode not recognizing that eslint is globally-installed
I just switched to volta from npm (THANK YOU!), but have run into an issue that confuses me — vscode doesn't seem to recognize that eslint is globally-installed, so the vscode-eslint extension won't lint my files, instead showing (in its console output):
Failed to load the ESLint library for the document (doc path)
To use ESLint please install eslint by running npm install eslint in the workspace folder app
or globally using 'npm install -g eslint'. You need to reopen the workspace after installing eslint.
But eslint is already installed globally, and if I open a vscode terminal and type eslint --version, I get back the version that it's running (v8.4.1, for what it's worth). Likewise, which eslint returns /Users/username/.volta/bin/eslint (with my username, obv).
I'm on macOS 11.6.1, running the latest vscode (v1.63.0) and vscode-eslint (v2.2.2).
I presume I could install eslint as a dev dependency in my Node project, but... I shouldn't have to, right? Vscode should be able to pick up that I have it installed globally?
Digging into this more — might this be the issue? It looks like the vscode-eslint extension uses npm config get prefix to resolve the location of globally-installed modules (specifically happening here in vscode-eslint, which then uses a vscode-languageserver-node method to run npm config get prefix and append /lib/node_modules/ to it).
If this is the case, is this even fixable by volta? I presume not...
Ran into this with VS Code and Prettier. The Prettier plugin gives you a way to specify a "prettier.prettierPath", but it has to point to a node_modules package. Since volta install only installs a binary ~/.volta/bin/prettier, the plugin can't resolve the path properly. My, admittedly hacky, workaround is to manually create a ~/.volta/sources folder with a package.json that lists the global version of Prettier that I need, then set "prettier.prettierPath": "~/.volta/source/node_modules/prettier".
It would be nice if Volta pulled down the Node package sources and cached them in ~/.volta somehow for use by editor plugins, but I think this is ultimately a problem with the VS Code plugin, not how Volta handles things.
ESLint + Volta + VSCode still doesn't work, unfortunately. I will probably have to stop using Volta due to this.
@Nettsentrisk Not sure if you raised this to the authors of vscode-eslint, but as I noted above (back in Dec 2021), the issue is in their library, and is present in a way that Volta can't do anything about. So if you have to abandon use of Volta as a result of this issue, it's probably worth mentioning to them, not the Volta authors.
Hopefully this will help others with the same problem. I managed to get Windows + Volta + ESLint global install to work in VSCode.
In VSCode settings (settings.json) configure a eslint.nodePath.
The "eslint.nodePath" is where the VSCode ESlint Extension looks for ESLint and ESLint plugins.
If Volta is your JavaScript Tool Manager and ESLint is installed globally then try
"eslint.nodePath": "C:\\Users\\<your-user-name>\\AppData\\Local\\Volta\\tools\\shared",
or
"eslint.nodePath": "/Users/<your-user-name>/AppData/Local/Volta/tools/shared",
If NVM is your Javascript Tool Manager and ESLint is installed globally then the eslint.nodepath may be something like `
"eslint.nodePath": "C:\Users\<your-user-name>\AppData\Roaming\nvm\v20.11.0\node_modules",
or
"eslint.nodePath": "/Users/<your-user-name>>/.nvm/versions/node/v20.11.0/bin/node",
To assist while debugging ESLint in VSCode add the following to the settings.json
"eslint.debug": true,
"eslint.trace.server": "messages",
and check the Output tab in VSCode and check the ESLint Task CTRL/CMD + SHIFT + P and find ESLint: Show Output Channel.
If ESLint is working you should be able to see linting errors in the Problems tab in VSCode.
If ESLint could search the Windows Path Environment Variable for nodePath it might simplify some of this config.
ESLint + Volta + VSCode still doesn't work, unfortunately. I will probably have to stop using Volta due to this.
@Nettsentrisk Did you switch to asdf or anything else? Because I have switched to asdf and I still see this error.
Not sure if it's my problem or not, but I don't want to use nvm again, it makes the terminal startup very slow.