visual studio code nodejs request 'launch': cannot launch target (reason: spawn node ENOENT) - node.js

When I use visual studio code to debug a nodejs app.
visual studio code tell me request 'launch': cannot launch target (reason: spawn node ENOENT)
My nodejs version is 4.2.4

Managed to get past this when running on Windows by specifying npm.cmd instead of npm in the VS code debug configuration like so
"runtimeExecutable": "npm.cmd",

Some discussions are posted in this here
How do I debug "Error: spawn ENOENT" on node.js?
Especially, the following points should be checked
Ensure the environment variable PATH is set
PATHEXT environment variable that can cause certain calls to spawn to not work on Windows.

I was getting this error on a Debian Linux system. I noticed the same thing worked OK on Windows.
Next I noticed that the Node.JS executable is called node on Windows but on Debian (and on Debian-based systems such as Ubuntu) it's called nodejs. So I created an alias - from a root terminal, I ran
ln -s /usr/bin/nodejs /usr/local/bin/node
and this solved the problem.

This usually happens if you already had your Visual Code Editor running while installing node js on Windows OS. I would advise you to shut down your Visual Studio Code and restart it. This problem should go away.
If not do a machine reboot and verify if the debug works flawlessly

Related

vscode crashes on Arch linux when opening file/folder

Installation vscode
I'm running Arch Linux (Manjaro) and installed vscode with:
sudo pacman -S code
but then a simple .NET core program resulted in
--------------------------------------------------------------------------------
You may only use the Microsoft .NET Core Debugger (clrdbg) with Visual Studio
Code, Visual Studio or Visual Studio for Mac software to help you develop and
test your applications.
--------------------------------------------------------------------------------
It seems like the official Microsoft build should be obtained via the snap store:
sudo snap install code --classic
And the program looks normal. I can install plug-ins, create a new file et cetera.
Problem
However, I cannot open any files or projects. Doing so results in vscode crashing. I read that code --disable-gpu could solve this problem, but doesn't do so for me.
Any ideas
what may cause this crash?
or how to get the pacman vscode working?
Logs
$ code --verbose
Gtk-Message: 22:59:19.805: Failed to load module "canberra-gtk-module"
Gtk-Message: 22:59:19.805: Failed to load module "canberra-gtk-module"
(code:33833): GdkPixbuf-WARNING **: 22:59:19.817: Cannot open pixbuf loader module file '/usr/lib/x86_64-linux-gnu/gdk-pixbuf-2.0/2.10.0/loaders.cache': No such file or directory
This likely means that your installation is broken.
Try running the command
gdk-pixbuf-query-loaders > /usr/lib/x86_64-linux-gnu/gdk-pixbuf-2.0/2.10.0/loaders.cache
to make things work again for the time being.
[33863:1104/225919.911481:ERROR:appcenter_api.cc(52)] expecting appcenter url prefix
[main 2020-11-04T21:59:19.960Z] Sending env to running instance...
[main 2020-11-04T21:59:20.041Z] Sent env to running instance. Terminating...
[main 2020-11-04T21:59:20.041Z] Lifecycle#kill()
where the recommended gdk-pixbuf-query-loaders > /usr/lib/x86_64-linux-gnu/gdk-pixbuf-2.0/2.10.0/loaders.cache results in bash: /usr/lib/x86_64-linux-gnu/gdk-pixbuf-2.0/2.10.0/loaders.cache: No such file or directory
I'm running Arch Linux (Manjaro) and installed vscode with:
sudo pacman -S code
but then a simple .NET core program resulted in
--------------------------------------------------------------------------------
You may only use the Microsoft .NET Core Debugger (clrdbg) with Visual Studio
Code, Visual Studio or Visual Studio for Mac software to help you develop and
test your applications.
--------------------------------------------------------------------------------
I had the same issue trying to get the debugger to work and I spent hours on finding the reason for this. What I found out is that the debugger only works with officially signed Microsoft binaries of VSCode. So you have to make a distinction here:
The package code contains the open source version of visual studio code, a build wich anyone can make using the provided sources by Microsoft. The program which you get here is therefore not signed by MS!
The package visual-studio-code-bin provided by the AUR contains a officially signed version by MS. If you use this package, the debugger works as expected.
I do not know wether snap - which I personally never used at all - provides this kind of package, so I can not tell anything about that, but using the said package from the user repository solved the problem for me reliably.
Try this one (which I installed just yesterday under the recent manjaro distribution and it worked fine) and see if this solves your problem with opening files and folders.

Node executable can't be found in Visual Studio Code

I'm using Visual Studio Code to (try to) debug my node.js scripts. On the moment I want to debug my index.js file, Visual Studio Code says 'Cannot find runtime 'node' on PATH. Is 'node' installed?
And the answer to this question is 'yes', because it can be found in my 'usr/local/bin' folder. And when I execute the commando 'echo $PATH' in my bash terminal, then I see this path is included (among others):
echo $PATH
/opt/local/bin:/opt/local/sbin:/Users/{myName}/anaconda3/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
Have also done some google searches on the issue but haven't been able to find a sound solution.
Can you please help?
Hans
For background info: I have installed Visual Studio Code via Anaconda and I'm using a Mac on 10.13.6 (MacOS Sierra).
I rather hoped there would be an answer better than the one I am about to give. For me over on Ubuntu 19.04, going through the install process for node fixed the issue; in my case, the PATH variable on my system was correct, and everything in ./.vscode/launch.json was correct. Defeated, I decided to reinstall node, and suddenly debugging worked despite the PATH being exactly the same afterwards. Never thought I would be debugging my debugger!

VSCode with WSL - How to use Bash for the launch configurations?

I use Visual Studio Code to develop a TypeScript Node application on Windows 10, with WSL enabled.
Thanks to other threads, I'm almost able to run a VSCode task with Bash on Ubuntu on Windows.
But now I try to do the same with a launch configuration. How can I make a launch configuration to use the node executable installed in WSL instead of the one installed on Windows?
If I run this command directly in the integrated terminal, with Bash, it works :
node src/start.js
But when I press "[F5]" and start a launch configuration that runs this same file, I get an error : "Error: %1 is not a valid Win32 application". This is because the oracledb library is used and has been compiled in Bash, not in Windows.
How can I make a launch configuration use Bash to run Node?
UPDATE : I opened an issue about that on VSCode's GitHub page.
Not if sure you still need help.
open bash outside of the vs code.
then run the following command, to install node.
sudo apt install nodejs-legacy
and you should be able to run node with bash in vs code.

Using Visual Studio Code on Windows with Ubuntu-Bash and NodeJS

I'm trying to figure out how to do my web development on Windows using the relatively new Windows Subsystem for Linux (Bash on Ubuntu on Windows) in conjunction with Visual Studio Code. I've configured the IDE to use the Bash in its integrated terminal, and I've set the project up such that the files are accessible in both the Linux and Windows file system.
The last thing I want to get set up is to get the IDE set up with NodeJS, but not NodeJS for Windows. I want it to use an installation of NodeJS in the Linux Subsystem. Does anyone know if it's possible to point VS Code to the Node installation in the Linux Subsystem?
This was a stumbling block for me too, until I found out that the real problem is that there's a pathing issue with WSL that creates a conflict if you already have NPM installed for Windows. Hopefully you've already figured this out yourself, but for anyone else who hits this, I'm copying in an excerpt from my longer guide on Visual C + WSL that's specific to this problem alone.
Given what you've said, I'll assume you already have node and NPM already installed in WSL's Ubuntu.
Using your favorite CLI editor (such as nano, vim, emacs, cat and sed… etc), open your ~/.profile
nano ~/.profile
Note: do NOT attempt to edit Linux files using Windows tools. (Thanks to #david-c-rankin's comment for the official link with the bold red text explaining this) If you don't want to use a CLI editor for this in the terminal, see the bottom of the answer this is excerpted from for a link on how to get a GUI one running.
Currently, the default bash PATH variable in WSL is
PATH="$HOME/bin:$HOME/.local/bin:$PATH"
Which is injecting the windows path after the first two binary directories. Unfortunately, this doesn't result in /usr/bin being used before the windows installed npm, so add that before the final $PATH:
PATH="$HOME/bin:$HOME/.local/bin:/usr/bin:$PATH"
Save out, and then either reload the terminal or just source the path file
source ~/.profile
VSCode (v1.18) now has better WSL support for Node:
I use nvm to install Node on Ubuntu, although it should work fine if you install it normally.
e.g.
nvm install 9.2.0
nvm alias default 9.2.0
From the VSCode docs
If you want to run Node.js in the Linux subsystem on Windows (WSL), you can use the approach from above as well. However to make this even simpler, we've introduced a useWSL flag to automatically configure everything so that Node.js runs in the Linux subsystem and source is mapped to files in your workspace.
Here is the simplest debug configuration for debugging hello.js in WSL:
{
"type": "node",
"request": "launch",
"name": "Launch in WSL",
"useWSL": true,
"program": "${workspaceFolder}/hello.js"
}
I opened bash outside of the vs code and run the following command, to install node.
sudo apt install nodejs-legacy
and I'm able to run node with bash in vs code.

nodejs: node-gyp rebuild - Access is denied

I am trying to install nodetime module to profile my nodejs app..
When i run > npm install nodetime
the files are downloaded. but when node-gyp rebuild runs.
I get the following error.
Command failed: CreateProcessW: Access is denied
The same thing happens, when i try to download v8-profiler.
Nodejs ver: 0.8.15
node-gyp: 0.7.1
I have tried this on both my dev machine that runs window 7 and on windows server 2008 where this app will be hosted..
Any help is appreciated. Please let me know if more explanation is required
Update:
Sorry I had ignored this post for a while.. Had a chat with someone I assume is the author of nodetime and here are the things required for nodetime to run on Windows.
Python version 2.7
If on windows the PATH environment variable for python should include python.exe Eg: C:\Python27\Python.exe
It requires CPP compilers that come with Visual C++ Express edition and Windows 7 64-bit SDK (SDK compiler is required for 64-bit version of nodejs).
Hope this helps.
Try just set PATH=C:\Python27;%PATH%
DO NOT set PYTHON variable (check that its not set on your machine).
I had incorrectly set the PYTHON variable some time ago - which then caused me this headache for ages until I managed to figure out what was wrong.

Resources