Sublime Forum

Eslint support for sublime text

#1

I am having trouble while using eslint and jshint and jsprettier in sublime text. I have installed the following packages in sublime text:

  • jsPrettier
  • SublimeLinter
  • SublimeLinter-eslint
  • SublimeLinter-jshint
  • SublimeLinter-flake8
  • AutoPEP8

I have installed eslint and jshint globally using npm with -g flag.
and also installed flake8 using pip

But when I am opening a .js file in sublime text I am getting the following error in my console:

SublimeLinter: WARNING: jshint cannot locate 'jshint'
Please refer to the readme of this plugin and our troubleshooting guide: http://www.sublimelinter.com/en/stable/troubleshooting.html
WARNING:SublimeLinter.plugin.jshint:jshint cannot locate 'jshint'
Please refer to the readme of this plugin and our troubleshooting guide: http://www.sublimelinter.com/en/stable/troubleshooting.htmlSublimeLinter: WARNING: eslint cannot locate 'eslint'
Please refer to the readme of this plugin and our troubleshooting guide: http://www.sublimelinter.com/en/stable/troubleshooting.html
WARNING:SublimeLinter.plugin.eslint:eslint cannot locate 'eslint'
Please refer to the readme of this plugin and our troubleshooting guide: http://www.sublimelinter.com/en/stable/troubleshooting.html
Package Control: Skipping automatic upgrade, last run at 2022-11-06 19:27:39, next run at 2022-11-06 20:27:39 or after

Also when I am running jsPrettier: Format Code from the command palate. I am getting the following error:

[JsPrettier ERROR]: Ensure Prettier is installed and defined in your environment PATH variable. You can optionally specify a custom path in 'JsPrettier.sublime-settings' using the 'prettier_cli_path' setting

I have correctly installed prettier globally using npm.
The linter is working fine for python files. Also autopep8 is working fine.

here is my PATH variable:

/home/aayush/.pyenv/shims:/home/aayush/.local/bin:/home/aayush/.miniconda3/condabin:/home/aayush/.nvm/versions/node/v19.0.0/bin:/home/aayush/.pyenv/bin:/home/aayush/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/aayush/.local/bin

I use nvm for managing nodejs and pyenv for python. I am easily able to access eslint, jshint, prettier and flake8 from command line.

Please help me to fix this issue.

0 Likes

#2

It looks like you are using NVM, so the node is not in PATH for ST unless you start it from the terminal.

0 Likes

#3

Though I can easily access node from command line. Here is the output of which node

/home/aayush/.nvm/versions/node/v19.0.0/bin/node

But if that would be an issue. I could not use flake8 and autopep8. I am also not using system python but I installed python through pyenv
Here is an output for pyenv which python, pyenv which autopep8 and pyenv which flake8 commands:

/home/aayush/.pyenv/versions/3.10.8/bin/python
/home/aayush/.pyenv/versions/3.10.8/bin/autopep8
/home/aayush/.pyenv/versions/3.10.8/bin/flake8
0 Likes

#4

Sure. That’s what NVM does. But if an app is not started from the command line, those NVM magics won’t happen. If you want to verify that, you can check ST’s PATH via the following in ST console

import os; print(os.environ['PATH'])
0 Likes

#5

The AutoPEP8 plugin ships autopep8 and use ST’s builtin python to execute it. Plus, it’s abandoned, see https://github.com/wistful/SublimeAutoPEP8.

0 Likes

#6

I got it. Is there any workaround for this? Or do I always have to install eslint per project locally?

0 Likes

#8

Borrowed from LSP’s docs:

https://lsp.sublimetext.io/troubleshooting/#updating-the-path-used-by-lsp-servers

OS …
Windows Open Start Menu, type “environment” and select “Edit environment variables for your account”. Modify the “Path” variable so that it includes the directory path to the program of your choice.
macOS Depending on your default shell, edit: ~/.profile (bash), ~/.zprofile (zsh) or ~/.config/fish/config.fish (fish).
Linux Edit ~/.profile.
1 Like

#9

I ditched nvm and now using volta. That solved the problem. volta uses shims and directly adds it’s shims directory to path same as pyenv.

Thanks

0 Likes