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

ESLint client: couldn't create connection to server. #1754

Closed
chrispalmo opened this issue Dec 15, 2023 · 13 comments
Closed

ESLint client: couldn't create connection to server. #1754

chrispalmo opened this issue Dec 15, 2023 · 13 comments
Labels
info-needed Issue requires more information from poster

Comments

@chrispalmo
Copy link

chrispalmo commented Dec 15, 2023

Issue Summary for vscode-eslint

Error Description

While using the ESLint extension in VSCode, the following errors are encountered:

  • ESLint server starts and stops immediately.
  • Error message: "couldn't create connection to server."
  • Issue with launching server using runtime node: "Error: spawn node ENOENT."
[Info  - 12:28:41] ESLint server is starting.
[Info  - 12:28:41] ESLint server stopped.
[Error - 12:28:41] ESLint client: couldn't create connection to server.
Launching server using runtime node failed. Error: spawn node ENOENT
[Error - 12:28:41] Starting the server failed.
Launching server using runtime node failed. Error: spawn node ENOENT
[Info  - 12:28:41] PATH environment variable is: /usr/bin:/bin:/usr/sbin:/sbin

Diagnostic Information

  • MacOS Sonoma 14.2 (23C64), Apple M1 Max
  • Node.js version: v18.18.2
  • Location of Node.js: /Users/cp/.npm/bin/node

Steps Taken to Resolve

  1. Node.js Installation Verification: Confirmed Node.js is installed and accessible via PATH.
  2. Updated PATH Variable: Verified Node.js path is included in the system's PATH.
  3. VSCode Settings for ESLint:
    • Tried various configurations for eslint.nodePath including empty, specific path and null.
  4. Reinstall ESLint Extension: Uninstalled and reinstalled the ESLint extension without resolution.
  5. Check and Update Node Version: Using n, updated and verified the Node version.
  6. ESLint Runtime Path Setting: Attempted setting eslint.runtime to the path of the Node executable.
  7. User Settings Configuration: Tested with different configurations in VSCode user settings.
  8. Permissions Check: Verified permissions for Node binary and relevant directories.
  9. Direct Execution in VSCode Terminal: Confirmed ability to run Node via VSCode terminal.
  10. Setting eslint.runtime to Null: Tried explicitly setting eslint.runtime to null.
  11. Permissions and Configuration:
  • Explored the possibility of permission issues with the Node binary and relevant directories.
  • Checked and confirmed proper read/write/execute permissions.
  • VSCode user configuration was modified and tested in various states, including removing all properties, without resolving the issue.

Additional Context

  • The Node.js installation was managed using n (version 8.2.0).
  • Fresh installation of VSCode
  • Potential issues with permission settings or VSCode user configuration were discussed but remain unresolved.

Conclusion

The issue seems to be a complex interaction between the VSCode ESLint extension, Node.js installation, and possibly VSCode's access to system variables or user settings. Despite multiple troubleshooting steps, the problem persists, indicating a need for direct intervention or guidance from the VSCode or vscode-eslint development team.

@tomasz-clipchamp
Copy link

tomasz-clipchamp commented Dec 15, 2023

I had the same issue, I managed to fixed it.

The problem is that ESLint does not use the terminal of your default choice and rather is using cmd (on windows/WSL), so while I was using node with Bash/Git for Windows via NVM. cmd didn't have access to node command

hence you get spawn node ENOENT error, as the default ESLint terminal doesn't recognize node command

The fix was really simple for me, just an install of node.exe via installation file rather than just using NVM. I confirmed by going to cmd and run node -v (when I had the error cmd was giving me invalid command, once installed I got node working), then restarting of vscode and the ESLint started working

please let me know if that works for you

@dbaeumer
Copy link
Member

Alternatively you can start VS Code from a command prompt which setups NVM correctly. And another question is why do you need a special node version to be used. Does the default provided by VS Code not work for you?

@chrispalmo let me know if that helps.

@dbaeumer dbaeumer added the info-needed Issue requires more information from poster label Dec 15, 2023
@chrispalmo
Copy link
Author

Just updated diagnostic info -- I’m using a Mac, MacOS Sonoma 14.2 (23C64), Apple M1 Max.

@chrispalmo
Copy link
Author

why do you need a special node version to be used

I don't, any version that works will do

Does the default provided by VS Code not work for you?

I don't quite understand what "default provided by VS Code" means. Does vscode ship with a builtin node runtime? If so, the extension doesn't seem to be finding it (it seems to be looking in /usr/bin:/bin:/usr/sbin:/sbin).

I don't necessarily need a special version. use n to manage node installations, and they live in /Users/cp/.npm/bin/node

@dbaeumer
Copy link
Member

@chrispalmo you somewhere set eslint.runtime to node which then force the client to look for that executable to launch the server. Simply remove that setting and the extension will use the node version that ships with VS Code.

@chrispalmo
Copy link
Author

In system Terminal app:

cp ~  $ which node
/Users/cp/.npm/bin/node

In file ~/Library/Application Support/Code/User/settings.json:

  1. comment out all existing settings
  2. add "eslint.runtime": "/Users/cp/.npm/bin/node",

Result same as before (on restarting VSCode and opening a project):

image
[Info  - 11:10:07] ESLint server is starting.
[Info  - 11:10:07] ESLint server stopped.
[Error - 11:10:07] ESLint client: couldn't create connection to server.
Launching server using runtime node failed. Error: spawn node ENOENT
[Error - 11:10:07] Starting the server failed.
Launching server using runtime node failed. Error: spawn node ENOENT
[Info  - 11:10:07] PATH environment variable is: /usr/bin:/bin:/usr/sbin:/sbin

@dbaeumer
Copy link
Member

dbaeumer commented Dec 19, 2023

Something seems off with your settings. If you setup a eslint.runtime and that runtime isn't found then it should print that path in the output channel and not simply node. In the screen shot below I set eslint.runtime to /tmp/node and here is what is printed to the output channel

[Info  - 10:48:59 AM] ESLint server is starting.
[Info  - 10:48:59 AM] ESLint server stopped.
[Error - 10:48:59 AM] ESLint client: couldn't create connection to server.
Launching server using runtime /tmp/node failed. Error: spawn /tmp/node ENOENT
[Error - 10:48:59 AM] Starting the server failed.
Launching server using runtime /tmp/node failed. Error: spawn /tmp/node ENOENT
[Info  - 10:48:59 AM] PATH environment variable is: <remove due to PII>

@chrispalmo
Copy link
Author

Got it.

Someone added "eslint.runtime": "node" to the repo root level .vscode/settings.json, and this was taking precedence over user settings. Interesting that this wasn't reportedly causing any issues for other devs.

Deleting the property from .vscode/settings.json resolved the issue.

Thanks Dirk for helping me figure this out :)

@chrispalmo
Copy link
Author

The bit I still don't understand, which stopping me from arriving at a long term solution fix (that doesn't involve breaking the plugin for for every other dev working on the project) is why "eslint.runtime": "node" doesn't resolve as expected:

In both the system terminal, and in the vscode terminal:

$ which node
/Users/cp/.npm/bin/node
$ node -v
v18.18.2

Setting "eslint.runtime": "node" is having issues, whereas directly setting

"eslint.runtime": "/Users/cp/.npm/bin/node"

Works fine.

@chrispalmo
Copy link
Author

chrispalmo commented Dec 20, 2023

@chrispalmo
Copy link
Author

As I seem to be the only person in the org experiencing this issue, the workaround I have been using is to delete .vscode/settings.json from .vscode/settings.json, and then git update-index --assume-unchanged .vscode/settings.json. This help prevent me from accidentally committing the change in unrelated prs, however can can make switching between branches tedious because I still need to remember to go back and manually revert the change before changing branches - so not a great long-term solution.

With my limited understanding of how vscode plugins work, I'm unsure if it would make sense for me to also open an issue with https://github.com/microsoft/vscode. Thoughts @dbaeumer?

@dbaeumer
Copy link
Member

dbaeumer commented Jan 8, 2024

@chrispalmo can you try to start VS Code from a terminal where which node resolve to a node version. Looks like VS Code doesn't source the environment correctly which results in not finding node on the PATH.

@chrispalmo
Copy link
Author

Running code from from a terminal with node in the PATH resolved the issue. Thanks @dbaeumer!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

3 participants