Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sublime Text - Tools > Build System > New Build System

Build Tools for Sublimetext

  • Add new build systems via Tools > Build System > New Build System.
  • Save files as Language.sublime-build
  • Any commandline tool for compiling code can be used.
  • Cmd + B (OSX) will build files and send output to the Sublime Console

Example Files

Submlime Examples

Sublime Settings

Here you can see where to create new builds and to setup automatic build types. Sublime Build Menu

// Sublime Text - Build System for Javascript
{
"cmd": ["node", "$file"],
"selector": "source.js"
}
// Sublime Text - Build System for PHP
{
"cmd": ["php", "$file"],
"selector": "source.php"
}
@carmanchris31

This comment has been minimized.

carmanchris31 commented Aug 30, 2016

I have Node installed via HomeBrew and Sublime wasn't reading my shell PATH variable so I had to add a path variable to the build file like so:

// Sublime Text - Build System for Javascript
{
    "cmd": ["node", "$file"],
    "selector": "source.js",
    "path": "$PATH:/usr/local/bin/"
}
@brandl3s

This comment has been minimized.

brandl3s commented Sep 25, 2016

Can anyone explain this? "[Errno 2] No such file or directory: 'node'"

@TravisIngram

This comment has been minimized.

TravisIngram commented Oct 27, 2016

Hi, @brandl3s. Using the method posted in this Gist requires you have Node.js installed on your computer. It's what Sublime will execute the JavaScript file. If you haven't installed Node yet, you'll have to do that first.

The error message you received is saying that the system doesn't know what 'node' is, that it can't find the installation. So, much like carmanchris31 above, you'll need to provide the file path that Sublime should use to find your Node installation.

If you have Node installed, you can run the terminal command, which node to determine the path to your installation. You can then replace node with that path and things ought to work correctly.

Here's what mine build file looks like.

// Sublime Text - Build System for JavaScript
{
  "cmd": ["/usr/local/bin/node", "$file"],
  "selector": "source.js"
}

The one carmanchris31 posted above should also work.

Hope that helps.

@aruprakshit

This comment has been minimized.

aruprakshit commented Aug 23, 2017

This is super helpful for me.. Never delete it. :)

@abuabu1717

This comment has been minimized.

abuabu1717 commented Sep 5, 2017

Thanks @TravisIngram!! New to programming. I did exactly as you said, worked!

@huezoaa

This comment has been minimized.

huezoaa commented Sep 9, 2017

Thanks @corbanb and @TravisIngram.

@shiju-sr

This comment has been minimized.

shiju-sr commented Dec 19, 2017

How do we add a python virtual environment

@wzup

This comment has been minimized.

wzup commented Jun 20, 2018

Doesn't work. SyntaxError: Unexpected token :

/Library/Application Support/Sublime Text 3/Packages/User/nodejs.sublime-build:2
  "cmd": ["/usr/local/bin/node", "$file"],
       ^

SyntaxError: Unexpected token :
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:616:28)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:191:16)
    at bootstrap_node.js:612:3
[Finished in 0.1s with exit code 1]
@Sol3y

This comment has been minimized.

Sol3y commented Sep 15, 2018

hey @wzup this instructions might help you -

  1. Open your sublime
  2. Open a .js file
  3. Tools > Build System > Select your custom build system (the one you created earlier).
  4. Try again to run your program (CTRL+B - shortcut for windows)

sublime build

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