ternjs / tern_for_sublime

Sublime Text package adding Tern support
MIT License
801 stars 52 forks source link

Node not found on Linux #67

Closed ghost closed 9 years ago

ghost commented 9 years ago

Hi, I was having problems running this plugin on Linux, Ubuntu 14.10 to be specific, due to the fact that ST3 doesn't run ~/.bashrc and thus node (which was installed using nvm) was not found in PATH. One solution was to add the absolute path in the "tern_command" setting like this: "tern_command": ["/home/husam/.nvm/versions/v0.12.0/bin/node", "/home/husam/.nvm/versions/v0.12.0/bin/tern"] which I found is inconvenient, and can be problematic if that version of node was deleted or if users sync their Preferences.sublime-settings file between different OSs.

Another solution that I found that can be more convenient is changing the start_server function in tern.py file as follows:

def start_server(project):
  if not tern_command: return None
  if time.time() - project.last_failed < 30: return None
  bash = None
  env = None
  if platform.system() == "Darwin":
    env = os.environ.copy()
    env["PATH"] += ":/usr/local/bin"
  elif platform.system() == "Linux":
    # Run node from interactive bash shell which will run node from bashrc
    bash = ['/bin/bash', '-i', '-c', " ".join(tern_command) +
            " ".join(tern_arguments)]
  proc = subprocess.Popen(tern_command + tern_arguments if bash == None else bash,
                          cwd=project.dir, env=env,
                          stdin=subprocess.PIPE, stdout=subprocess.PIPE,
                          stderr=subprocess.STDOUT, shell=windows)

 #Rest of the code
marijnh commented 9 years ago

I don't think joining command-line arguments with a space is the same as passing them separately, so this seems like a rather scary approach. Systems also aren't guaranteed to have a /bin/bash.

ghost commented 9 years ago

Good point. It was just frustrating getting it to work under ubuntu.

Keep up the good work, mate.

ghost commented 9 years ago

Just an update in case someone else runs in the same problem. Since I had similar issues with other plugins.

the problem was running ST from the unity launcher which loaded ST from /bin/sh the problem can be solved by running ST with the subl command from the terminal. Or using a quick fix by editing /usr/share/applications/sublime_text.desktop file and changing the Exec argument from Exec=/opt/sublime_text/sublime_text %F to Exec=/bin/bash -i -c /opt/sublime_text/sublime_text %F

hope this helps. Husam