Problems with LESS Sublime Text Build System - node.js

On OS X 10.7.2, I created a small build system in Sublime Text 2 that will compile my LESS files into CSS for me, but it seems to be having a problem.
{
"cmd": ["/usr/local/lib/node_modules/less/bin/lessc", "-x", "$file", "$file_path/$file_base_name.css"],
"selector": ["source.less"]
}
I've installed Node.js v0.6.6 using the standard OS X installer package, and installed less v1.1.6 using npm into the /usr/local/lib/node_modules folder. Switching to my build system works fine, but when I attempt to run the build I get the following error message:
[Finished]env: node: No such file or directory
Running the command from the terminal works perfectly fine, it's just Sublime that is taking issue.

Another way to solve this is to install LESS globally, as it looks like you've already done:
npm install -g less
Then pass shell=true as a variable in the build script:
{
"shell" : true,
"cmd": ["lessc", "-x", "$file", "$file_path/$file_base_name.css"],
"selector": "source.css.less"
}
That runs the lessc command in the terminal in a way you'd expect.

While I am still unsure as to why there is a difference between Sublime Text 2 and running the build system in the terminal, I fixed the issue I was encountering by explicitly adding the value of $PATH to my build system.
Acting on the documentation provided on the Sublime Text Help page, I set up my build system to be the following:
{
"cmd": ["/usr/local/lib/node_modules/less/bin/lessc", "-x", "$file", "$file_path/$file_base_name.css"],
"selector": "source.css.less",
"path": "/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin: No such file or directory"
}

Related

VSCode integrated terminal failed to launch

VSCode integrated terminal failed to launch and the error showed up:
The terminal process failed to launch: Path to shell executable "bash" is not a file of a symlink.
Tried to look for solution in official troubleshoot page but can't really figured the cause of the problem.
Starting an external terminal (gnome-terminal) using CtrlAltT is fine.
Also tried to re-install VSCode, removing cache etc. still the same issues. Happens to almost all my Ubuntu computer.
There is a similar fix in Windows https://stackoverflow.com/a/64020049/16346600, but how to do it in Linux? More particularly I can't find this terminal.integrated.shell.linux.
OS: Ubuntu18.04 LTS
VSCode: Version 1.57.1
It seems like VSCode somehow cannot find the path to executable for default profile "bash".
I fix by providing the exact binary path to bash.
Inside settings.json:
"terminal.integrated.profiles.linux": {
"bash": {
"path": "/bin/bash"
},
...
}

ST3 Build System : prevent Node.js to come back to prompt after execution

When I execute a script with Node.js in command prompt lets say like that :
c:\> node a_script.js
It just exits when the script is ended which is boring because I d'like to test some variables values. I can't find any option using node --help to avoid that, do you know a way ?
I want to do a Sublime Text Build System
{
"cmd": ["start", "cmd", "/k", "C:/progra~2/nodejs/node.exe", "$file"],
"selector": "source.js",
"shell" : true
}
My script is executed but it exit just after. I expect to go back to REPL but node.exe closes once it has executed my script.
The solutions provided by the following question didn't worked :
How do I load my script into the node.js REPL? since most of the time it implies to type some command in the REPL
I also tried to use --interactive but no luck.
I solved my problem by installing replpad with npm
npm install -g replpad
And using the following build system :
{
"shell" : true,
"cmd": ["start", "cmd", "/k", "replpad", "$file_path"],
}
that's a bit weird is that I need to save the file once replpad has been loaded but it works

Visual Studio Code to use node version specified by NVM

Is it possible for VS Code to use node version specified by NVM?
I have 6.9.2 installed locally. Even after switching to another version, from the OS X terminal (not the VS Code terminal), restarting VS Code, VS Code still shows using 6.9.2.
OS X terminal
MacBook-Pro-3:~ mac$ node -v
v7.8.0
VS Code Terminal
MacBook-Pro-3:QB-Invoice-API mac$ node -v
v6.9.2
In VS Code:
go to your launch.json file
add the runtimeVersion attribute inside configurations as shown below
In this example, we are assuming 4.8.7 is already installed using nvm:
{
"version": "<some-version>",
"configurations": [
{
"type": "node",
"runtimeVersion": "4.8.7", // If i need to run node 4.8.7
"request": "launch",
"name": "Launch",
"program": "${workspaceFolder}/sample.js"
}
]}
The solution is to set alias default. In the OS terminal run -
nvm alias default 7.8.0
Open vscode, now running node -v returns 7.8.0
It seems vscode takes up this (alias default) value and not the node version that is set by nvm use X.X.X
Restart VS code for it to pick up the changes.
add runtimeExecutable to your .vscode/launch.json like this
{
"type": "node",
"request": "launch",
"name": "App",
"program": "${workspaceRoot}/index.js",
"runtimeExecutable": "${env:HOME}/.nvm/versions/node/v6.9.2/bin/node"
}
I had the same problem of being unable to keep my node version specified trough nvm in my OS X environment not only with VSCode but also with Atom Editor (using the platformio-ide-terminal package for managing the integrated terminal in it). None of the suggestions in the previous answers worked for me, besides me not using the debugger but using gulp and grunt for specific tasks. Apparently nvm does not get along with the integrated terminals or sub shells at least in these editors because when loading them the environment variable $PATH is modified internally and does the following according to a comment by one of the contributors of this package in this issue reported here NVM fails to load within nested shell #1652:
" #charsleysa I know why nvm is throwing this error. In your subshell, somehow the /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin part of your PATH has been moved from the end of the PATH to the start.
When nvm is then started, it calls nvm_change_path (my contribution changed it to this from nvm_prepend_path), which modifies the nvm-relevant part of the path in place.
Nvm then checks the current npm prefix by asking npm what it is. Since /usr/local/bin/npm now has precendence, it reports /usr/local/bin.
Nvm then checks whether the current prefix as reported by npm is in the directory tree of the current nvm node version (at this stage, the installation directory of the node version your default nvm alias resolves to).
The prefix is not part of that tree, so it deactivates itself (calling nvm_strip_path in the process, which is why there's no nvm-related path in your subshell's PATH), and bails with the error you're getting.
macOS's /etc/profile (or /etc/zprofile) calls /usr/libexec/path_helper, which does the PATH switcheroo.
In the parent shell, the PATH doesn't yet have an nvm dir in it, so by the time nvm runs, it prepends its directory to the path. But in the subshell, PATH has been reconfigured by macOS to put any non-system directories at the end and we have the problem."
I was always getting this message when launching any integrated terminal:
nvm is not compatible with the npm config "prefix" option: currently set to "/usr/local"
Run npm config delete prefix or nvm use --delete-prefix vx.x.x --silent to unset it.
What I did to solve this in my case was the "workaround" part of that same issue reported which is essentially the following:
Reset the path by adding the following line inside my ~/.bash_profile at the very top before anything else:
PATH="/usr/local/bin:$(getconf PATH)"
And after that no more warnings when I launch any integrated terminal on both editors and I can interact with nvm to switch between any node version easily and without problems at all.
Here it is another alternative just in case this one doesn`t help that much.
Some of the answers provided are correct and upvoted, but somewhat incomplete. This procedure worked for me:
Open the terminal window inside VS Code and run node -v. You'll get for instance v10.12.0.
Open a terminal window outside VS Code Change your node version with nvm (ie. nvm use v12.14.0)
Cmd+ Shift + p and choose Preferences > Open Settings (JSON)
Add "terminal.integrated.shellArgs.osx": [] to your user config
Cmd+ Shift + p and choose Shell Command: Install 'code' command in PATH
Close VS Code.
Open a terminal window and run code. This will open VS Code with a new and updated bash / zsh session.
Open the terminal window inside VS Code and run node -v. You'll get v12.14.0.
Bonus: If you always want to get a particular node version on VS Code's terminal, set it as default by opening a terminal window outside VS Code and running:
nvm alias default v12.14.0
I am using oh-my-zsh and it too was not using the node version specified by nvm. Tried several suggestions posted here, but the only way I managed to resolve this issue was by adding the following line to the top of ~/.zshrc
PATH="/usr/local/bin:$(getconf PATH)"
I had the same problem, but the above answers didn't help.
Apparently the default shellArgs for osx are set to bash while I'm using zsh. I solved the problem by setting the shellArgs in my user settings to an empty array:
"terminal.integrated.shellArgs.osx": []
A alternative solution I've found is to simply launch code from the shell after you pick your node using nvm.
You need to first open the command pallet and select "install 'code' into
path".
And then launch a terminal and select your node via nvm and then launch "code".
I had this same issue and I found a strange workaround that may be helpful to someone else in the future.
If I do not set eslint.runtime my system was running node v10.11.0 for eslint server, whereas I wanted it to be running v12.13.0 which I had installed and made default via nvm.
I found that the v10 version of node was installed by brew based on #franziga's answer but my desired version of node was installed by nvm. So, I uninstalled v10.11.0 via brew and closed/reopened VS Code. Strangely, eslint was still reporting that it was started using v10.
I tried running a shell without any changes to my PATH in any startup scripts, and the version of node was still correctly pointed to v12 as expected, but VS code still starts up v10 for eslint.
I'm not sure how to check the path of the executable that is being run by eslint, and if I open an integrated terminal everything works fine with the expected version of node (v12).
Solution (for me):
I found that if I set "eslint.runtime": "node" in settings.json that it will now use whatever version of node was active when I opened vscode using code . on the terminal. Just "node" - no path.
Lots of complicated answers here. In my case, this was caused by node having previously having been installed. Fixed it by deleting the following directories: rm -rf /usr/local/bin/npm and rm -rf /usr/local/bin/node, then running nvm use default in VSC to pick up the node version installed by nvm.
Particularly with the shell I had no problems, but you may:
check your shell is properly configure or change it (you might be using different shells for vscode or your terminal)
check your env and if it's not properly set use the terminal.integrated.env.<platform>
I had issues with vscode itself and no solution could help me. So I finished using the following launch script.
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/server.js",
"runtimeExecutable": "/bin/bash",
"runtimeArgs": ["-c", ". ~/.nvm/nvm.sh;nvm run default \"$#\"", "dummy"]
},
this assumes you have it configure for bash (otherwise change it to your shell) and you want to use the default node version as configured by nvm (you may also change it).
Note: The "dummy" parameter is required so the rest of the parameters are properly parsed.
A longer explanation of "dummy": Shell scripts use positional parameters where the first one will be the script location itself (addressed by $0), when using the -c flag the script is read inplace an there is no $0 being set. vscode will pass some arguments, like the node start script location which will be wrongly interpreted, so "dummy" pushes all parameters one spot. It can be just anything, but it must be there.
Setting the default alias only worked for me after closing all instances of VS Code. Simply reloading the window wouldn't work. nvm ls would show the default alias set correctly but would keep using the version set when VS code was first opened (across all windows).
There's also the issue of having multiple node versions across repos, which is really what nvm is meant to solve. In the end I added the following to the bottom of my .zshrc file:
[ -s "./.nvmrc" ] && nvm use
Essentially when a new shell starts, it checks to see if a non-empty .nvmrc exists in the current directory and if so, uses that version. If that version is not installed you will get a message saying so. After running nvm install it should load properly in all new terminal sessions.
You can also use the automatic version switching on directory changes shown in the nvm README as #asiera pointed out. Although a project terminal will typically always open in the same directory as your .nvmrc file, so this solution is a bit simpler and only runs on terminal startup.
I found that setting the node version locally in a sub shell before calling code works well, while not changing the version in the current shell, e.g.
$ (nvm use 14; code .)
Therefore, to make it work transparently for any project folder, create a file .precode in the project folder with shell commands to source before starting code - e.g.,
nvm use 14
Then add to ~/.bashrc
pre_code(){
if [ $# == 1 ] && [ -f ${1}/.precode ] ; then
echo "(source ${1}/.precode ; `which code` ${#})"
(source ${1}/.precode ; `which code` ${#})
else
`which code` ${#}
fi
}
alias code='pre_code'
(Note: Run source ~/.bashrc in any shell opened before the edit in order for the edit to take effect.)
Then, assuming the necessary file ~/myproject/.precode exists, starting code with
$ code ~/myproject
will result in some diagnostic output on the shell, e.g.
source github/myproject/.precode
Now using node v14.15.1 (npm v6.14.8)
as well launching a new vscode window with the correct node version in the terminal window and debugger. However, in the shell from which it was launched, the original node version remains, e.g.
$ node -v
v12.19.1
I tried all the suggested solutions but nothing was working.
/usr/local/bin/node was pointing to somewhere. i made a symlink to a specific nvm node folder and that was solving the issue for me:
ln -s /Users/mad/.nvm/versions/node/v11.1.0/bin/node /usr/local/bin/node
I have the same problem and I found that I have node installed by brew and nvm. I uninstalled node installed by brew and the versions on both terminal and visual studio code are the same now.
You don't need to modify your default node version. The following example assumes that node 6 is your default version and you want VSCode to reference version 7 of node:
# open a terminal instance
nvm use 7
code . # or project folder instead of "."
# when VSCode start, you may use ctrl+` to open the integrated terminal
# then check the node version in the integrated terminal
node -v # should print 7
After reading this thread and testing almost all suggestions, I found a very simple solution if you are using nvm: Add nvm use in the command.
It's gonna take a little more time to start the debugger, but it is worth it to me because now I don't have to execute nvm use and open Vscode by the terminal every time I start working on a different project.
Here is my .vscode/launch.json file. Good luck!
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"command": "nvm use && yarn start",
"name": "Launch",
"request": "launch",
"type": "node-terminal",
},
]
}
I wanted the solution to be workspace specific and not requiring any action on my part (not having to redo nvm use <version> each time i start a terminal)
The solution I found:
create the .nvmrc file at the root of my project that old the node version I want to use as stated in nvm ReadMe
adding the automatic activation script in my ~/.zshrc also in the ReadMe (bashrc script also in the readme)
So, your nvm is configured well, but other version of node STILL keeps taking over?
Remove all non-nvm versions of node:
brew uninstall --force node (yarn will be fine without system node)
Other version installed from pkg or other non-nvm method
Re-login. Now, nothing can be fighting for path with nvm no matter how is shell launched.
Note: When installing/upgrading yarn, use brew install yarn --without-node
VSCode Shell args seems to be deprecated, here's update using profiles in VS Code's settings.json:
This gets rid of the -l terminal argument turning it into an interactive shell vs a login shell.
"terminal.integrated.profiles.osx": {
"zsh (normal - me)": {
"path": "zsh",
"args": []
}
},
"terminal.integrated.defaultProfile.osx": "zsh (normal - me)"
Thanks! the answers here for explanation and here for old args way:
For me I simply did:
# in a separate terminal (i.e not in VScode teminal)
nvm install <node version>
then in VScode terminal:
nvm use <the node version you installed>
In case you'd like to set the Node version for your Visual Studio Code NPM script runner, here's what works on a per-project basis. So, without having to set global nvm defaults.
By "NPM script runner" I mean the hover-and-execute-scripts functionality directly in package.json:
Step-by-step
Place an .nvmrc file containing the project's Node version into the root folder of your project.
Enable automatic environment as described here: https://github.com/nvm-sh/nvm#deeper-shell-integration.
Open VS Code's settings.json and define your preferred shell (in my case, it's zsh). For the automation profile, it's important to define a login and interactive shell (arguments -l and -i):
"terminal.integrated.automationProfile.osx": {
"path": "/bin/zsh",
"icon": "play",
"args": ["-l", "-i"],
},
"terminal.integrated.profiles.osx": {
"bash": null,
"zsh": {
"path": "/bin/zsh",
"icon": "star",
}
},
Result
Opening a new shell triggers NVM (The icons show which setting is working):
And running an NPM script triggers NVM:
Cheers!
following solution worked for me
first install and use the desired node version with nvm with these commands: nvm install v16.13.1 and nvm use v16.13.1.
then get the pathname of the currently using node with which node command on Linux.
it will be something like this /usr/local/nvm/versions/node/v16.13.1/bin/node
finally use this pathname in launch.json for runtimeExecutable option.
the launch.json file
{
"version": "0.2.0",
"configurations": [
{
"type": "pwa-node",
--> "runtimeExecutable": "/usr/local/nvm/versions/node/v16.13.1/bin/node",
"request": "launch",
"args": ["testcode/hunter.js","127.0.0.1:9229"],
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/index.js"
}
]
}
If none of this answers worked for you,
If you have previously installed node by downloading and unzipping it.
Go to usr/local/lib and there will be this guy sitting around named nodejs.
Kick him out.
And set nvm alias default to preferred version again.
That's it, happily ever after. At least worked for me though.
According to the docs of nvm, you need to add this code snippet to your ~/.bashrc, ~/.profile, or ~/.zshrc file, so open the file and paste this in, restart vscode and enjoy nvm
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
source: https://github.com/nvm-sh/nvm#manual-install
Did not tried all of the solution, but for me updating nvm simply worked.
Just follow the installation here and make sure that you bash_profile is updated.
None of the other solutions worked for me.
So I ran nvm alias default node and this fixed it for me.
I tried several of the options here at the top and they didn't work. I found a simple solution. In the VS Code terminal:
Click the down arrow on the terminal dropdown
Select Default Shell
Select 'bash'
Try node -v and that should return the correct version that was set as default nvm alias default v12.14.0
Check your default interactive shell on your MAC.
If it's zsh, how about setting the terminal in VS Code to zsh mode as well? Then you can use the specified node version on the Mac. This works for me.
I'm using macOS Big Sur v11.2.1 + VS Code v1.55.1
Setting pictrue
sudo rm -rf /usr/local/opt/node#<YOUR_NODE_VERSION>
then restart the Visual Code

Sublime Text 3: Node.JS Build System

I'm trying to make a Node.js build system for SB3 on Mac Yosemite. Here is my Node.Sublime-Build:
{
"cmd": ["/usr/local/bin/node", "$file"],
"selector": "source.js"
}
Writing just 'node' returns an error, that node isn't found. I quickly checked in terminal "Which node" and it returned /usr/local/bin. I switched to the above code and now the build just returns "finished in x.0s".
Even if I simply console.log, it just returns "finished in x.0s".
Also, I checked that node is working on my computer (from console, and it is returning my console.log()s). What might I be missing?
Thanks all!
This is a bit...ridiculous on my part. It seems you must first save the file before you can build system. I just wanted to test the environment and thought setting the build system would be enough.
Saving the file and then building solved the problem
*facepalm

Getting SublimeText2 to compile Typescript

Really excited about using Typescript on the Mac however, even after a full day of troubleshooting, unable to get it to compile in SublimeText. Followed these directions (the first at the top) to install nodes and npm>
https://gist.github.com/isaacs/579814
Installed Typescript
sudo npm install -g typescript
Installed the syntax highlighting package for sublime
http://msopentech.com/blog/2012/10/01/sublime-text-vi-emacs-typescript-enabled/
Created a build file 'typescript.sublime-build as follows
{
"selector": "source.ts",
"cmd": ["tsc", "$file"],
"path": "/usr/local/bin",
"file_regex": "^(.+?) \\((\\d+),(\\d+)\\): (.+)$"
}
When I type $which node I get
/usr/local/bin/node
When I type $which tsc I get
/Users/<username>/local/bin/tsc
BUT, whenever I try to compile even the simplest .ts file in SublimeText the first effort message I get is
[Errno 2] No such file or directory
Can anyone suggest further troubleshooting steps?
I struggled with a little too. It seems the PATH is quite different when trying to run commands directly from the build system than the terminal, and this is a cause of problems.
What I did as a simple workaround was just set my command to run a Bash script, i.e. in the sublime.project file have the command as..
"cmd": ["./build.sh"]
.. and then in the build.sh script in my project folder simply run the compiler, i.e..
#! /bin/bash
tsc --target ES5 foo.ts
Obviously this assumes foo.ts pulls in all the other project files so they get compiled (or you could glob for the files on the command-line seeing as you're running a Bash command).
This might be a quick and simple solution for you.
You could do what my team mates do. Use Sublime Text for text editing with a grunt watch in the background compiling any files that change : https://github.com/basarat/grunt-ts

Resources