Sublime Text CoffeeScript build system: `env: node: No such file or directory`

CourtDemone picture CourtDemone · Nov 19, 2013 · Viewed 45.8k times · Source

I'm trying to set up a CoffeeScript build system in Sublime Text 3, but I keep getting the following error:

env: node: No such file or directory
[Finished in 0.0s with exit code 127]
[cmd: ['coffee', '-o','/Users/jcourtdemone/Sites/autotempest.com/new_design_sandbox/static/script', '-cw', '/Users/jcourtdemone/Sites/autotempest.com/new_design_sandbox/static/coffee']]
[dir: /Users/jcourtdemone/Sites/autotempest.com/new_design_sandbox/static/coffee]
[path: /usr/bin:/bin:/usr/sbin:/sbin]

My build system looks like this:

{
    "name": "Coffee - AT",
    "cmd": ["coffee","-o","${project_path:${folder}}/static/script","-cw","${project_path:${folder}}/static/coffee"],
    "selector": "source.coffee",
    "path":"/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/lib/node_modules/coffee-script/bin"
}

Two things strange about this.

1) It says it's looking in /usr/bin where a symlink to coffee exists.

2) Because of (1), I overrode $PATH to include the actual location of coffee which is /usr/local/lib/node_modules/coffee-script/bin, but for some reason, $PATH isn't being overridden properly, it's sticking with the default $PATH.

Things to note:

i) I've verified that all paths are correct and pass normally through a regular terminal command.

ii) Tried with a "shell": true variable in the build system.

iii) I have another build system for Compass like this that works fine.

Anyone run into similar problems or issues? Any ideas?

Answer

MattDMo picture MattDMo · Nov 19, 2013

In Terminal, type which node, then create a symlink to that location in /usr/bin. For example, if node lives in /usr/local/bin, create the symlink like so:

sudo ln -s /usr/local/bin/node /usr/bin/node

If you look at the source of your coffee script, you'll probably find that the first line is something along the lines of:

#!/usr/bin/env node

Exit code 127 in Sublime means that an env command has failed - so in your case, the build system is finding coffee, but it can't execute it because the node binary isn't in Sublime's default search path.

There are two ways to redefine the default search path for Sublime. The first (and easiest) is to always open it from the command line using the built-in subl command. If you're an OS X power user and don't mind messing with important system settings, check out my post on unix.SE on how to alter the default /usr/bin:/bin:/usr/sbin:/sbin path that you're seeing. Be forewarned that if you don't do things correctly, you may break your system. However, if you're running Mountain Lion (10.8.X) and you follow the instructions exactly, everything should be fine. (I haven't upgraded to Mavericks, so no guarantees on whether it'll work with that version.)