Sublime Text 3: Build System - node.js. NPM module not executing
Solution 1
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
}
}
Solution 2
Following worked for me in Sublime Text 3 on Windows
- Tools -> Build System -> New Build System...
- Enter the below text in the new file
- Save the file as "nodejs.sublime-build"
{ "shell_cmd": "node ${file}", "selector" : "source.js" }
Prerequisite is to have node.js installed
Solution 3
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.
Solution 4
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.
Solution 5
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.
Related videos on Youtube
todd.pund
Financial Research Developer (II) at Maritz Financial. One wife, two step children, one grandmother, 2 dogs, and a cat. Sometimes I sleep.
Updated on August 18, 2020Comments
-
todd.pund over 3 years
I'm trying to execute node-dev in a sublime text 3 build system. node-dev is in my path:
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.
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.
-
vmx over 10 yearsCan you try updating full path of
node-dev
in cmd tag? Eg:["c:\nodejs\bin\node-dev", "$file"]
-
-
Tarik over 9 yearsI think this should have been marked as answer. It solved my problem. Thanks!
-
VictorKilo almost 9 yearsI 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}\""
-
Green over 8 yearsWhere is that
.sublime-build
file on Windows? It is not in\AppData\Roaming\Sublime Text 3\Packages
-
Peteris about 8 yearsI had to use the following
{ "shell_cmd": "node ${file/ /\\\\ /}", "selector" : "source.js" }
because Sublime Text would otherwise not parse empty spaces in the filename. -
Anwar almost 8 yearsWorks in Linux, too
-
daronwolff over 7 yearsI used
"cmd": ["node", "$file"],
instead ofnode-env
. Thanks -
DrBug almost 6 yearsActually this is the only way to make it work in Windows 10 and ST3
-
OdatNurd over 4 yearsUsing 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; theshell_command
is passed to the system to interpret so it's the system command processor that has a problem. Better to usenode \"$file\"
instead so that the filename is quoted for the shell (the regex also works but arguably quoting is a bit easier to interpret).