9

I'm trying to execute node-dev in a sublime text 3 build system. node-dev is in my path:

cmd node-dev diplay

Yet when I run this build script:

{
  "cmd": ["node-dev", "$file"],
  "selector": "*.js"
}

I get this error, which also shows that npm is in my path.

npm in path img

yet when I run with the same build script using node instead of node-dev it executes just fine.

I've also tried to include the "path" variable pointing at the node-dev bin folder, which didn't help at all.

Any help would be appreciated. Thanks.

2
  • Can you try updating full path of node-dev in cmd tag? Eg: ["c:\nodejs\bin\node-dev", "$file"] Commented Dec 30, 2013 at 19:59
  • Note: (added 2023-02-17) Some content in this thread may reference stale links to the SublimeText docs. Readers may experience better results by replacing BEFORE http://docs.sublimetext.info/en/latest with AFTER https://docs.sublimetext.io/guide. Also known as: "Sublime Text Community Documentation" Commented Feb 17, 2023 at 15:09

5 Answers 5

21

Following worked for me in Sublime Text 3 on Windows

  1. Tools -> Build System -> New Build System...
  2. Enter the below text in the new file
  3. Save the file as "nodejs.sublime-build"
{
  "shell_cmd": "node ${file}",
  "selector" : "source.js"
}

Prerequisite is to have node.js installed

Sign up to request clarification or add additional context in comments.

3 Comments

I had to use the following { "shell_cmd": "node ${file/ /\\\\ /}", "selector" : "source.js" } because Sublime Text would otherwise not parse empty spaces in the filename.
Works in Linux, too
Using a bare $file is not recommended because as @Peteris noted, it doesn't handle spaces in file names properly. That's not a Sublime thing though; the shell_command is passed to the system to interpret so it's the system command processor that has a problem. Better to use node \"$file\" instead so that the filename is quoted for the shell (the regex also works but arguably quoting is a bit easier to interpret).
17

Sublime text docs:

https://www.sublimetext.com/docs/build_systems.html

shell

Optional. If true, cmd will be run through the shell (cmd.exe, bash…)

Try to add "shell : true

{
  "cmd": ["node-dev", "$file"],
  "selector": "source.js",
  "windows" : {
     "shell": true
  }
}

3 Comments

I think this should have been marked as answer. It solved my problem. Thanks!
Where is that .sublime-build file on Windows? It is not in \AppData\Roaming\Sublime Text 3\Packages
I used "cmd": ["node", "$file"], instead of node-env. Thanks
6

The command is incorrect for Sublime Text 3 :)

This is one example of running node as build system:

{
    "shell_cmd": "taskkill /F /IM node.exe & node ${file}"
}

Please note that the array-version doesn't work like in Sublime Text 2.

2 Comments

I think you should add some [escaped] quotes around ${file}. If there are any spaces in the file path the command is broken. "shell_cmd": "taskkill /F /IM node.exe & node \"${file}\""
Actually this is the only way to make it work in Windows 10 and ST3
2

For macOS, this worked for me on Sublime Text 3:

{
    "cmd": ["node","$file","$file_base_name"],
    "working_dir": "${project_path:${folder}}",
    "selector":"source.js"
}

Selector Note

My selector setting was:

"selector":"*.js"

and OdatNurd advised that:

The reason is that the selector is not correct; it doesn't match file names, it matches syntax scopes (i.e. it's based on the syntax in use regardless of file extension); changing it to source.js from *.js should get it working.

Comments

1

If you are a windows user.

Try applying the following snippet

{
    "selector": "source.js",
    "cmd": ["C:\\Program Files\\nodejs\\node", "<", "$file"],
    "windows": {
        "shell": true
    }
}

Save this as node.sublime-build file.

For more info you can refer to http://docs.sublimetext.info/en/latest/ for more.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.