Skip to content

Instantly share code, notes, and snippets.

@corbanb
Last active August 25, 2024 00:42
Show Gist options
  • Save corbanb/d0d6bdcfbd8eb455ce99 to your computer and use it in GitHub Desktop.
Save corbanb/d0d6bdcfbd8eb455ce99 to your computer and use it in GitHub Desktop.
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
Copy link

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
Copy link

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

@TravisIngram
Copy link

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
Copy link

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

@abuabu1717
Copy link

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

@huezoaa
Copy link

huezoaa commented Sep 9, 2017

Thanks @corbanb and @TravisIngram.

@shiju-sr
Copy link

How do we add a python virtual environment

@wzup
Copy link

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]

@IMSoley
Copy link

IMSoley 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

@priya1712d
Copy link

'which node' command doesn't work for me. I am using windows 10. I could install node successfully and i can also see the installed version using node --version

@vijayjoyz
Copy link

What is source.js here?

@adeleke5140
Copy link

I'm on Ubuntu 18.04 and I tried the steps here. Unfortunately, nothing is showing in my console
node error

@Saurabh7339
Copy link

hey Folks, i was trying to use javascript for Competitive Programming . i can't find a way to take the input . I came across readline() function but this is not working in sublime-text3 . please help !

@alirezatc
Copy link

Where should we save the file in (macOS)?

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