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

SublimeLinter doesn't recognize linters installed with NVM #128

Closed
wldcordeiro opened this issue Aug 8, 2014 · 49 comments
Closed

SublimeLinter doesn't recognize linters installed with NVM #128

wldcordeiro opened this issue Aug 8, 2014 · 49 comments

Comments

@wldcordeiro
Copy link

I have a few linters installed with NVM (jshint, csslint) and Sublime Linter won't recognize them. I've added the path to my settings but according to my console SublimeLinter is still looking in the wrong place.

Here's my SublimeLinter settings.
https://gist.github.com/ec03df57e48eac45263b

@aparajita
Copy link
Contributor

NVM isn't supported.

@wldcordeiro
Copy link
Author

@aparajita That doesn't make much sense, if there's a setting for the path that should make it work. Why does the plugin keep looking in /usr/bin/env

@aparajita
Copy link
Contributor

That question can't be answered without seeing the complete debug output from the console.

@wldcordeiro
Copy link
Author

SublimeLinter: flake8 imported <module 'flake8.engine' from '/usr/local/lib/python3.4/dist-packages/flake8/engine.py'> 
SublimeLinter: pyyaml imported <module 'yaml' from '/usr/local/lib/python3.4/dist-packages/yaml/__init__.py'> 
SublimeLinter: ENV['GEM_HOME'] = 'None' 
SublimeLinter: jshint version query: /home/wldcordeiro/npm/bin/jshint --version 
SublimeLinter: WARNING: no jshint version could be extracted from:
/usr/bin/env: node: No such file or directory

@aparajita
Copy link
Contributor

That isn't the complete output. I need to see everything from startup.

@wldcordeiro
Copy link
Author

DPI scale: 1
startup, version: 3062 linux x64 channel: dev
executable: /opt/sublime_text/sublime_text
working dir: /
packages path: /home/wldcordeiro/.config/sublime-text-3/Packages
state path: /home/wldcordeiro/.config/sublime-text-3/Local
hardware concurrency: 8
zip path: /opt/sublime_text/Packages
zip path: /home/wldcordeiro/.config/sublime-text-3/Installed Packages
found 27 files for base name Default.sublime-keymap
found 4 files for base name Default.sublime-mousemap
found 57 files for base name Main.sublime-menu
loading pointer bindings
found 1 files for base name predawn.sublime-theme
loading bindings
theme loaded
app ready
wrote startup cache, added files: 10 orphaned files: 0 total files: 418 cache hits: 408
pre session restore time: 0.142069
using gamma: 1 (err: 0)
startup time: 0.262957
first paint time: 0.273019
launching: /opt/sublime_text/plugin_host
reloading plugin Default.block
reloading plugin Default.comment
reloading plugin Default.copy_path
reloading plugin Default.delete_word
reloading plugin Default.detect_indentation
reloading plugin Default.duplicate_line
reloading plugin Default.echo
reloading plugin Default.exec
reloading plugin Default.fold
reloading plugin Default.font
reloading plugin Default.goto_line
reloading plugin Default.history_list
reloading plugin Default.indentation
reloading plugin Default.kill_ring
reloading plugin Default.mark
reloading plugin Default.new_templates
reloading plugin Default.open_file_settings
reloading plugin Default.open_in_browser
reloading plugin Default.pane
reloading plugin Default.paragraph
reloading plugin Default.paste_from_history
reloading plugin Default.save_on_focus_lost
reloading plugin Default.scroll
reloading plugin Default.set_unsaved_view_name
reloading plugin Default.side_bar
reloading plugin Default.sort
reloading plugin Default.swap_line
reloading plugin Default.switch_file
reloading plugin Default.symbol
reloading plugin Default.transform
reloading plugin Default.transpose
reloading plugin Default.trim_trailing_white_space
reloading plugin CSS.css_completions
reloading plugin Diff.diff
reloading plugin HTML.encode_html_entities
reloading plugin HTML.html_completions
reloading plugin Better CoffeeScript.CoffeeScript
reloading plugin BracketHighlighter.bh_core
reloading plugin BracketHighlighter.bh_logging
reloading plugin BracketHighlighter.bh_plugin
reloading plugin BracketHighlighter.bh_regions
reloading plugin BracketHighlighter.bh_remove
reloading plugin BracketHighlighter.bh_rules
reloading plugin BracketHighlighter.bh_search
reloading plugin BracketHighlighter.bh_swapping
reloading plugin BracketHighlighter.bh_wrapping
reloading plugin BracketHighlighter.ure
reloading plugin CTags.ctags
reloading plugin CTags.ctagsplugin
reloading plugin CTags.test_ctags
reloading plugin CTags.test_ctagsplugin
reloading plugin ChangeQuotes.change_quotes
reloading plugin ColorPicker.sublimecp
reloading plugin Colorsublime.colorsublime-plugin
loaded 1290 snippets
reloading plugin Emmet.emmet-plugin
reloading plugin FindKeyConflicts.find_key_conflicts
reloading plugin Gist.gist
reloading plugin Gist.helpers
reloading plugin Gist.request
reloading plugin Gist.settings
reloading plugin Git.add
reloading plugin Git.annotate
reloading plugin Git.commit
reloading plugin Git.diff
reloading plugin Git.flow
reloading plugin Git.git
reloading plugin Git.history
reloading plugin Git.repo
reloading plugin Git.stash
reloading plugin Git.status
reloading plugin Git.statusbar
reloading plugin GitGutter.git_gutter
reloading plugin GitGutter.git_gutter_change
reloading plugin GitGutter.git_gutter_compare
reloading plugin GitGutter.git_gutter_events
reloading plugin GitGutter.git_gutter_handler
reloading plugin GitGutter.git_helper
reloading plugin GitGutter.view_collection
reloading plugin Markdown Preview.MarkdownPreview
reloading plugin Markdown Preview.helper
reloading plugin Markdown Preview.markdown_wrapper
reloading plugin Markdown Preview.settings
reloading plugin Package Control.Package Control
reloading plugin Restructured Text (RST) Snippets.footnotes
reloading plugin Restructured Text (RST) Snippets.headers
reloading plugin Restructured Text (RST) Snippets.helpers
reloading plugin Restructured Text (RST) Snippets.indent_list_item
reloading plugin Restructured Text (RST) Snippets.lists
reloading plugin Restructured Text (RST) Snippets.render
reloading plugin Restructured Text (RST) Snippets.simpleformat
reloading plugin Restructured Text (RST) Snippets.tables
reloading plugin SCSS.scss_completions
reloading plugin Schemr.schemr
reloading plugin SideBarEnhancements.Edit
reloading plugin SideBarEnhancements.SideBar
reloading plugin SideBarEnhancements.SideBarDefaultDisable
reloading plugin SideBarEnhancements.StatusBarFileSize
reloading plugin SideBarEnhancements.StatusBarModifiedTime
reloading plugin SublimeLinter-contrib-scss-lint.linter
SublimeLinter: scss linter loaded 
reloading plugin SublimeLinter-csslint.linter
SublimeLinter: csslint linter loaded 
reloading plugin SublimeLinter-flake8.linter
SublimeLinter: flake8 linter loaded 
reloading plugin SublimeLinter-jshint.linter
SublimeLinter: jshint linter loaded 
reloading plugin SublimeLinter-pyyaml.linter
SublimeLinter: pyyaml linter loaded 
reloading plugin SublimeLinter-ruby.linter
SublimeLinter: ruby linter loaded 
reloading plugin Sublimerge Pro.Sublimerge
reloading plugin Themr.themr
reloading plugin Vintageous.__init__
reloading plugin Vintageous.builder
reloading plugin Vintageous.dev_cmds
reloading plugin Vintageous.ex_commands
reloading plugin Vintageous.ex_main
reloading plugin Vintageous.ex_motions
reloading plugin Vintageous.jump_list_cmds
reloading plugin Vintageous.modelines
reloading plugin Vintageous.state
reloading plugin Vintageous.test_runner
reloading plugin Vintageous.toplist
reloading plugin Vintageous.xactions
reloading plugin Vintageous.xmotions
reloading plugin Vintageous.xsupport
reloading plugin Vintageous.xsupport_mouse
reloading plugin WordCount.WordCount
reloading plugin Anaconda.anaconda
reloading plugin Emmet Style Reflector.emmet_style_reflector
reloading plugin HTML-CSS-JS Prettify.HTMLPrettify
reloading plugin PlainTasks.PlainTasks
reloading plugin SublimeLinter.commands
reloading plugin SublimeLinter.sublimelinter
reloading plugin SublimeREPL.__init__
reloading plugin SublimeREPL.completions
reloading plugin SublimeREPL.lang_integration
reloading plugin SublimeREPL.run_existing_command
reloading plugin SublimeREPL.sublimerepl
reloading plugin SublimeREPL.sublimerepl_build_system_hack
reloading plugin SublimeREPL.text_transfer
plugins loaded
schemr ready
themr ready
SublimeLinter: debug mode: on 
SublimeLinter: temp directory: /tmp/SublimeLinter3 
SublimeLinter: find_python(version='3', script=None, module=None) 
SublimeLinter: find_python: requested version = {'minor': None, 'major': 3} 
SublimeLinter: user shell: /bin/bash 
SublimeLinter: computed PATH using /bin/bash:
~/npm/bin/
/usr/local/sbin
/usr/local/bin
/usr/sbin
/usr/bin
/sbin
/bin
/usr/games
/usr/local/games

SublimeLinter: find_posix_python: python3 => /usr/bin/python3 
SublimeLinter: find_python: system python = /usr/bin/python3 
SublimeLinter: find_python: available version = {'minor': 4, 'major': 3} 
SublimeLinter: find_python: <= ('/usr/bin/python3', None, 3, 4) 
SublimeLinter: sys.path for /usr/bin/python3:
/usr/lib/python3.4
/usr/lib/python3.4/plat-x86_64-linux-gnu
/usr/lib/python3.4/lib-dynload
/usr/local/lib/python3.4/dist-packages
/usr/lib/python3/dist-packages

SublimeLinter: flake8 imported <module 'flake8.engine' from '/usr/local/lib/python3.4/dist-packages/flake8/engine.py'> 
SublimeLinter: pyyaml imported <module 'yaml' from '/usr/local/lib/python3.4/dist-packages/yaml/__init__.py'> 
SublimeLinter: ENV['GEM_HOME'] = 'None' 
Emmet: No need to update PyV8
SublimeLinter: found existing Rails syntax, version 1 
found 57 files for base name Main.sublime-menu
SublimeLinter: found existing HTML syntax, version 3 
['git', 'push']
Package Control: Installing 1 upgrades
ignored packages updated to: [Markdown, Vintage, Sublimerge Pro]
reloading Packages/Sublimerge Pro/Custom Comparisons.sublime-settings
unloading plugin Sublimerge Pro.Sublimerge
reloading Packages/Sublimerge Pro/Sublimerge.sublime-settings
generating syntax summary
found 27 files for base name Default.sublime-keymap
found 4 files for base name Default.sublime-mousemap
found 56 files for base name Main.sublime-menu
found 1 files for base name predawn.sublime-theme
reloading Packages/Sublimerge Pro/Custom Comparisons.sublime-settings
reloading Packages/Sublimerge Pro/Sublimerge.sublime-settings
generating syntax summary
found 26 files for base name Default.sublime-keymap
found 3 files for base name Default.sublime-mousemap
loading pointer bindings
theme loaded
loading pointer bindings
reloading Packages/User/Preferences.sublime-settings
found 1 files for base name predawn.sublime-theme
theme loaded
Package Control: Upgraded Sublimerge Pro to v2.8.9
ignored packages updated to: [Markdown, Vintage]
found 1 files for base name predawn.sublime-theme
reloading Packages/User/Package Control.sublime-settings
reloading Packages/Sublimerge Pro/Custom Comparisons.sublime-settings
reloading plugin Sublimerge Pro.Sublimerge
reloading Packages/Sublimerge Pro/Sublimerge.sublime-settings
generating syntax summary
found 27 files for base name Default.sublime-keymap
found 4 files for base name Default.sublime-mousemap
found 57 files for base name Main.sublime-menu
reloading Packages/Sublimerge Pro/Custom Comparisons.sublime-settings
reloading Packages/Sublimerge Pro/Sublimerge.sublime-settings
found 27 files for base name Default.sublime-keymap
found 4 files for base name Default.sublime-mousemap
theme loaded
loading pointer bindings
reloading Packages/User/Preferences.sublime-settings
loading pointer bindings
found 1 files for base name predawn.sublime-theme
theme loaded

@aparajita
Copy link
Contributor

Like I said at the beginning, nvm isn't supported. I kind of knew what I was talking about.

nvm works by modifying PATH (or by looking at a .nvmrc file) in the current shell, and thus is only effective when running node from the shell. SublimeLinter isn't running in your shell's environment, it's running in Sublime Text's environment, which is inherited from the shell it is launched from. But if the application is launched, it doesn't inherit from a shell.

The first line of jshint is #!/usr/bin/env node. Within Sublime Text, /usr/bin/env will look in PATH that is set by SublimeLinter, which knows nothing about nvm. Adding ~/npm/bin to the paths doesn't help because that isn't where nvm puts node executables, it's something like ~/.nvm/v0.11.0/bin/node.

So like I said, nvm isn't supported currently because it only works within the exact shell from which you issue commands. In fact, even within a shell, as soon as you open a new shell, it has no idea that nvm has modified PATH. You can have different versions of node running in different shells simultaneously. So how is SublimeLinter supposed to know which one you want it to use?

Support could be added for .nvmrc files, but that will have to be done by someone else. This is open source, I welcome contributions.

@majimboo
Copy link

+1

@aparajita
Copy link
Contributor

@majimboo Sorry to say that votes won't help. Someone (other than me) has to come forward and implement nvm support.

@drgullin
Copy link

drgullin commented Oct 6, 2014

This code works well for the latest node installed through nvm:

"paths": {
    "linux": [],
    "osx": [
        "~/.nvm/v0.10.32/lib/node_modules/jshint/bin"
    ],
    "windows": []
},

@majimboo
Copy link

majimboo commented Oct 6, 2014

Actually this can easily be fixed by aliasing the version with nvm to default. Restart. Profit.

@borestad
Copy link

borestad commented Nov 4, 2014

This is one of the (many) reasons I use n instead of nvm:
https://github.com/tj/n
Works flawless with sublime

This may also be an option (haven't tried it myself)
https://github.com/isaacs/nave

@andrewdeandrade
Copy link
Contributor

For those interested in this issue, you may want to check out the NodeLinter class I added recently. It's a work in progress, but I'm looking to support the following features:

  • local binary support (not only global binaries)
  • setting to only enabling a linter if that linter is a dependency or devDependency
  • don't disable the linter if the global binary is missing, but a local binary exists.

I don't see any reason why nvm support couldn't be added to the NodeLinter class.

Another great feature, which some might think goes too far, but would be super cool would be to have a mapping from module name to sublimelinter plugin and automatically install a missing linter plugin (disabled by default of course) if it detects that a Node project depends on that linter.

https://github.com/SublimeLinter/SublimeLinter3/blob/master/lint/node_linter.py

@ruimarinho
Copy link

From my experience, there is absolutely no problem using nvm with SublimeLinter. Here's the no-frills edition for those using zsh and iojs. Your mileage may vary for other combinations.

  • Install nvm (I've opted for the homebrew version):
brew install nvm
  • Install iojs:
nvm install iojs
nvm use iojs
  • Make sure your .zshenv sets up the environment correctly (snippet sourced from the wonderful prezto framework):
# Ensure that a non-login, non-interactive shell has a defined environment.
if [[ "$SHLVL" -eq 1 && ! -o LOGIN && -s "${ZDOTDIR:-$HOME}/.zprofile" ]]; then
  source "${ZDOTDIR:-$HOME}/.zprofile"
fi
  • Load the nvm script from ~/.zprofile. I personally prefer setting the NVM_DIR env var to my home dir, but this is entirely optional:
# Set download dir
export NVM_DIR=~/.nvm

# Load nvm script
if [[ -s $(brew --prefix nvm)/nvm.sh ]]; then
  source $(brew --prefix nvm)/nvm.sh
fi
  • Install the linter modules you want to have available through SublimeLinter. I've chosen jshint and jscs. The -g arguments makes it a global installation, so the binaries will be available at ~/.nvm/versions/io.js/v1.2.0/bin/ due to my NVM_DIR setting.
npm install -g jshint jscs
  • Open Sublime Text 3, install SublimeLinter, then SublimeLinter-jshint and lastly SublimeLinter-jscs. That's it!
  • Lint away :)

Hope this helps!

@vasyan
Copy link

vasyan commented Feb 21, 2015

@majimboo It's works great! Thanks.

@andycaramba
Copy link

It works for me

"paths": {
    "linux": [],
    "osx": [
        # I have installed jshint here
        "/PATH/TO/HOMEDIR/node_modules/.bin/",
        # Without this line a got error
        # SublimeLinter: WARNING: no jshint version could be extracted from:
        # env: node: No such file or directory
        "/PATH/TO/HOMEDIR/.nvm/current/bin/"
    ],
    "windows": []
},

@cvbuelow
Copy link

I was having issues but once I did nvm alias default v0.12.1 all was good

@chrisl8
Copy link

chrisl8 commented Aug 11, 2015

I solved this problem by adding the following:

export NVM_DIR="${HOME}/.nvm"
[ -s "$NVM_DIR/nvm.sh"  ] && . "$NVM_DIR/nvm.sh"  # This loads nvm
nvm use stable

to ~/.bash_profile
as explained here:
http://www.sublimelinter.com/en/latest/troubleshooting.html#adjusting-shell-startup-files

I think the problem is solved by the documentation, but I hope my comment will help others who find their way here via web search.

@chauthai
Copy link

chauthai commented Sep 8, 2015

@chrisl8 thanks for your help!
It seems Sublime Text defaults to the bash shell on MacOSX even if you set zsh as your default shell in Terminal.
Your solution finally enabled my eslint!

@arxpoetica
Copy link

Fixed my problem too. Thx.

@thymikee
Copy link

Anyone having problems with @chrisl8 answer not working on OSX:

  1. If you use zsh paste this export NVM_DIR="${HOME}/.nvm" into ~/.zprofile (create if not present)
  2. Cmd+Shift+P, search for SublimeLinter: Clear Caches and clear the cache.

@amir-rahnama
Copy link

@aparajita Why not supported? Isn't it as simple as what HTML Prettify guys did by introducing a way to have a config saying where node is installed if its not installed already?

@groteworld
Copy link
Member

Not saying it can't be done, just saying it isn't currently. If it seems simple, please feel free to contribute! Thanks!

@btmurrell
Copy link

@borestad, thanks for the pointer to n this kicks ass over nvm, and as advertised works seamlessly with sublime.

@leomeloxp
Copy link

Did what @thymikee suggested and it fixed it for me. I guess it makes sense that sublime doesn't look at zshrc or bashrc, since at least on linux only .*profile gets read when you log in and startx.

@groteworld
Copy link
Member

[REDACTED COMMENT]

@YRodriguezO, Please watch your language, that is not appropriate behavior.

@jawshooah
Copy link
Contributor

@YRodriguezO That kind of language is not welcome here, and your comment is incoherent besides. Please leave.

@wldcordeiro
Copy link
Author

So since people have posted workarounds I'm closing the issue.

@vogelino
Copy link

@chrisl8 Mine too! Thx!

With ❤️ with two years delay!

@nodkrot
Copy link

nodkrot commented Jul 25, 2016

Here is what I did (sort of the combination). In your ~/.zprofile:

#
#  NVM
#

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

And then Cmd+Shift+P, search for SublimeLinter: Clear Caches and clear the cache. (not sure if this was necessary).

I use zsh with prezto this is my .zshenv

#
# Defines environment variables.
#
# Authors:
#   Sorin Ionescu <sorin.ionescu@gmail.com>
#

# Ensure that a non-login, non-interactive shell has a defined environment.
if [[ "$SHLVL" -eq 1 && ! -o LOGIN && -s "${ZDOTDIR:-$HOME}/.zprofile" ]]; then
  source "${ZDOTDIR:-$HOME}/.zprofile"
fi

@lvl99
Copy link

lvl99 commented Aug 17, 2016

I saw that there was a point on the SublimeLinter-jshint page:

If you are using nvm and zsh, ensure that the line to load nvm is in .zshenv and not .zshrc.

I then added my nvm initialiser shell script (the line above which @nodkrot has written) into the .zshenv file, cleared SublimeLinter's cache and restarted Sublime 3. I had SublimeLinter's debug mode on and it was able to locate node via nvm in the path with no errors locating my all my linter plugins too.

@sorenlouv
Copy link

sorenlouv commented Sep 9, 2016

This is how I solved it:

Open "SublimeLinter Settings" and add path to Node:

"paths": {
    "linux": [],
    "osx": ["~/.nvm/versions/node/v4.5.0/bin"],
    "windows": []
},

And remember to read the docs :)

@newhouse
Copy link

newhouse commented Dec 23, 2016

For me, like @nodkrot , the problem was that I was using NVM and ZSH. In fact, I'm using Oh My Zsh as well.
I simply had to move the NVM stuff from .zshrc to .zprofiile, restart ST3, and it was fine. This is because .zshrc isn't loaded by the shell that Sublime uses I guess.

By the way, this was also staring me in the face in the SublimeLinter-eslint docs:

"If you are using nvm and zsh, ensure that the line to load nvm is in .zprofile and not .zshrc."

This problem was, I believe, also exacerbated by the fact that I had no "system" installation of Node...otherwise this would have presented itself differently, or not at all since it would have found a node.

@flyskywhy
Copy link

with version 4.0.5, paths eg "linux":["~/.nvm/v0.11.0/bin/node"] can't work anymore, I have to

sudo ln -s ~/.nvm/v0.11.0/bin/node /usr/bin/node

@kaste
Copy link
Contributor

kaste commented Mar 7, 2018

I thought that this is documented in the README, but it isn't. Happy to take documentation PRs.

Here is some info for the new SL4

https://github.com/SublimeLinter/SublimeLinter-eslint/blob/4ecc891b6162e242b2d91a6c435e7ec68e29036a/messages/4.0.1.txt#L24-L36

@elmigranto
Copy link

elmigranto commented Mar 13, 2018

Worked for me:

  • open your shell with PATH set as you want it
    (pointing to correct node, etc.);
  • execute subl
    (which is cli command to launch Sublime Text);
  • ...
  • PROFIT!!1.!!!

@JakobJingleheimer
Copy link

JakobJingleheimer commented Mar 28, 2018

This sounds like it could be caused by sublimehq/sublime_text#1877

For me, I get the error in the OP, but then SublimeLinter kicks in after a few seconds.

@brainthinks
Copy link

@kaste - thank you! Here is how I got my n installation to work:

"linters": {
  "eslint": {
    "disable": false,
    "args": [],
    "excludes": [],
    "env": {
      "PATH": "/home/user/n/bin:$PATH"
    }
  }
}

I got the path to my n node executable by running:

which node

@theSekyi
Copy link

@brainthinks what does $PATH do? Do I add it to the end of my which node output?

@maxmckenzie
Copy link

I do not think it is a good idea. as most comments here suggest to add "osx": ["~/.nvm/versions/node/v4.5.0/bin"], to your sublime lint conf

note the hardcoded version of node that is referenced node/v4.5.0

maybe you're just working on a single app. Maybe your only using one version of node for all you developer needs.

but as this is related with nvm one assumes there are multiple versions of node in play.

on linux you just reference .nvm in your home folder "linux": ["/home/xam/.nvm"],

Rather than running eslint against a specific version of node each time as is the case with the above.

@rreckonerr
Copy link

rreckonerr commented May 14, 2018

Had the same problem running Linux Mint 18.3 and node installed with nvm.
First problem I got was SublimeLinter: WARNING: jshint cannot locate 'jshint'. To fix it add

    "paths": {
        "linux": [
            "~/.nvm/versions/node/v8.11.1/bin",
        ],
        "osx": [],
        "windows": []
    },

to your ~/.config/sublime-text-3/Packages/User/SublimeLinter.sublime-settings or Preferences > Package Settings > SublimeLinter > Settings.

And the second problem was /usr/bin/env: ‘node’: No such file or directory. Fixed it by adding to the same SublimeLinter user settings file:

  "linters": {
       "jshint": {
           "disable": false,
           "args": [],
           "excludes": [],
           "env": {
               "PATH": "~/.nvm/versions/node/v8.11.1/bin:$PATH"
           },
       },
   },

@brainthinks Thank you for the "PATH": "/home/user/n/bin:$PATH"

@trisweb
Copy link

trisweb commented Nov 30, 2018

@rreckonerr's solution fixed SublimeLinter using the wrong node version for me, which resulted in the error "SyntaxError: Use of const in strict mode." in case anyone else is encountering that. Sticking the nvm path in there works just fine.

@eriku
Copy link

eriku commented Jan 23, 2019

Installing this fixed it for me: https://github.com/int3h/SublimeFixMacPath

@mklef121
Copy link

Had the same problem running Linux Mint 18.3 and node installed with nvm.
First problem I got was SublimeLinter: WARNING: jshint cannot locate 'jshint'. To fix it add

    "paths": {
        "linux": [
            "~/.nvm/versions/node/v8.11.1/bin",
        ],
        "osx": [],
        "windows": []
    },

to your ~/.config/sublime-text-3/Packages/User/SublimeLinter.sublime-settings or Preferences > Package Settings > SublimeLinter > Settings.

And the second problem was /usr/bin/env: ‘node’: No such file or directory. Fixed it by adding to the same SublimeLinter user settings file:

  "linters": {
       "jshint": {
           "disable": false,
           "args": [],
           "excludes": [],
           "env": {
               "PATH": "~/.nvm/versions/node/v8.11.1/bin:$PATH"
           },
       },
   },

@brainthinks Thank you for the "PATH": "/home/user/n/bin:$PATH"

This Worked for me.

@bebbi
Copy link

bebbi commented Mar 11, 2019

Solutions like what @mklef121 quotes seem to depend on timing in some ways. They only work intermittently for me in an nvm setup.

The one @eriku posted is the first that appeared to work consistently for me.

@isalikov
Copy link

isalikov commented May 21, 2019

You can setup symlink for current nvm version of node to /usr/local/bin in your ~/.zshrc

ln -sf /Users/iknpx/.nvm/versions/node/$(nvm current)/bin/node /usr/local/bin/node

@lopezdp
Copy link

lopezdp commented Dec 9, 2019

Had the same problem running Linux Mint 18.3 and node installed with nvm.
First problem I got was SublimeLinter: WARNING: jshint cannot locate 'jshint'. To fix it add

    "paths": {
        "linux": [
            "~/.nvm/versions/node/v8.11.1/bin",
        ],
        "osx": [],
        "windows": []
    },

to your ~/.config/sublime-text-3/Packages/User/SublimeLinter.sublime-settings or Preferences > Package Settings > SublimeLinter > Settings.

And the second problem was /usr/bin/env: ‘node’: No such file or directory. Fixed it by adding to the same SublimeLinter user settings file:

  "linters": {
       "jshint": {
           "disable": false,
           "args": [],
           "excludes": [],
           "env": {
               "PATH": "~/.nvm/versions/node/v8.11.1/bin:$PATH"
           },
       },
   },

@brainthinks Thank you for the "PATH": "/home/user/n/bin:$PATH"

@rreckonerr This solution worked for me on macOS Catalina on zsh terminal and nvm. Thank you!

@nodesocket
Copy link

nodesocket commented Nov 28, 2022

Also confirm the following below env works instead of adding nvm setup to .zprofile. Set the following in SublimeLinter.sublime-setting:


"jshint": {
    "@disable": false,
    "args": [],
    "excludes": [],
    "env": {
        "PATH": "/Users/justin/.nvm/versions/node/v14.20.1/bin:$PATH"
    }
},

Obviously replace the username justin and version of node v14.20.1 above.

@mattpr
Copy link

mattpr commented Jul 22, 2024

I know this is a super old (recurring) topic...but there aren't any solutions that allow SublimeLinter to use project-specific node versions in parallel (different node versions). So I'll add one.

This isn't exactly sublimelinter's problem...but it is a general problem as more languages move towards project-specific interpreter/runtime versions and project-specific dependencies (python venv, nodejs .nvmrc, etc). The linter/linter-version may be project-specific dependency rather than a global install (supports CI, common basis for teams, etc). The project linter version may depend on a specific interpreter/runtime version (python, nodejs, etc). A system may have many different versions of an interpreter/runtime installed and different mechanisms to activate a given version for a project (venv, nvm, etc).

There is a reasonable work-around that allows you to use multiple different node versions (via nvm) in sublime in parallel. Only downside is that it requires using sublime-project files (open as project instead of dir) in order to have project-specific linter configs (PATHs) (ie different node versions for different projects).

Sublime/linter are not nvm-aware...they just rely on Sublime sourcing dotfiles at startup and then finding stuff on the PATH.
So you need to look for ways to make sure your PATH is updated in the right places so that the node/npm version found first on the PATH is the one you want.

only one node version across all of sublime (not optimal)

So sublime sources your dotfiles on startup...so it will get PATH/etc from there...to ensure that sublime (and therefore sublimelinter) can find the node version you want.

(aside) If your linter is completely broken (e.g. eslint not found) it is likely just a dotfile problem with overwriting PATH or not setting NVM vars correctly.

However! The point of nvm is that you can run multiple version of node/npm in parallel. The above means you get a single node/npm version for all of sublime-land. Which is not a problem if you only work on a single project with a single version of node/npm at a time.

Keep in mind that it is best to avoid using global modules and use project specific modules/dependencies/versions so that tests are predictable (for instance if you have eslint as part of acceptance test before committing to git and your production build system uses eslint 9+ and you are testing locally with eslint <9...there are a lot of differences).

If you can live with only one project (and node version) at a time, then you can use:

export NVM_SYMLINK_CURRENT=true  # creates $NVM_DIR/current/bin/ symlink pointing at latest nvm use version
nvm use    # run from your project dir.  assuming you have .nvmrc in your project dir specifying project version.

...and THEN start sublime (so /current/ symlink is in place before sublime starts). In your dotfiles you should make sure to add the symlink to the front of your path.

PATH="${NVM_DIR}/current/bin/:$PATH"

This will ensure that whatever the latest nvm use was (in any terminal) is always showing up as the current node version for all terminals/apps as default (nvm use modifies the current terminal/session's PATH and overrides this by adding another segment to the beginning of PATH).

You also need to make sure you aren't re-running nvm in your dotfiles if nvm is already initialized. ie default nvm dotfile stuff needs to be wrapped in some check (like if NVM_DIR already set, don't do anything). Reason why is that sublime sources your dotfiles at startup and so may re-write the .nvm/current symlink based on Sublime's own env which is likely not the same as your project/terminal env. This may or may not work depending on the extent of NVM setup in the environment sublime inherits from the process that launches it.

If you have 2 different node projects open at the same time that each use a different node version, then just relying on single/global sublime PATH to pick the right node version won't cut it.

multiple node (via nvm) versions in parallel in sublime

Alternatively... if you can live with opening Sublime project files instead of opening project folders (I find this annoying to remember), you can use <project-name>.sublime-project files in each project in order to override the sublime PATH on a per-project basis. Alone, this would involve hard-coding nvm version bin dir paths into your project file...which is not sharing/check-in friendly.

So I also add some preparation on the npm package side that we can then use in our sublime project file.

For instance, I've setup my .npm-init.js to:

  • add special prepare script to project package.json (runs before lots of things like npm install)
    • "prepare": "source $HOME/.nvmrc; nvm use; NODE_DIR=$(dirname $(nvm which --silent)); ln -s \"$NODE_DIR\" ./.node_dir ",

Note that I moved the nvm dotfile stuff into a dedicated .nvmrc file which is sourced from normal profile files as needed. So I can source this nvm bit directly without all the other bash/zsh profile stuff being run at the same time. (Always good idea to not let nvm auto-edit your dotfiles if you have any special include structures or run dual bash/zsh environments.)

This creates a special directory symlink .node_dir pointing to the current nvm bin dir (should be per .nvmrc). Can name it what you want. My .npm-init.js also does...

  • desired node version in .nvmrc
  • engines node version in project package.json (matches nvmrc)
  • engine-strict=true in project .npmrc (so npm install will fail if wrong node version is in use)
  • add my node dir symlink to .gitignore
  • creates a <myproj>.sublime-project file in the project directory
    • to tell SublimeLinter to use a path (for this project) that includes our project-specific node symlink dir.

example sublime-project file

{
    "folders":
    [
        {
            "path": "."
        }
    ],
    "settings":
    {
        "SublimeLinter.linters.eslint.enabled": true,
        "SublimeLinter.linters.eslint.env": {
            "PATH": "${folder}/node_modules/.bin:${folder}/.node_dir/:${PATH}"
        },
    }
}

With all that you get a working sublime project out of the box (after npm init) assuming you have nvm on your system. But you do need to open from the project menu rather than opening dir from file menu...otherwise the sublime project file is ignored and the paths set there for your linters are not picked up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests