Why VSCode keeps using old node.js version on nvm? - visual-studio-code

I have an issue on node.js debugging on vscode, it no matter what I do persists on a particular node.js version on nvm.
lets say I have the following simple launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "webpack launch",
"program": "npx",
"args": [
"webpack",
"serve",
"--config",
"config/webpack.config.dev.js",
"--port",
"3051",
],
"autoAttachChildProcesses": true,
"stopOnEntry": true
},
note: this has been working completely fine until I recently changed nvm version mainly I use and on an other computer.
if you run the above "webpack launch" debug, in the debug console, it shows:
/home/user/.nvm/versions/node/v13.10.1/bin/node npx webpack serve --config config/webpack.config.dev.js --port 3051
well, I'm not using v13.10.1 anymore, but v17.9.0. I'm saying this for a countless times, vscode. lets do the steps I'm doing to tell vscode to not to use the old version but the v17.9.0 version:
.bashrc
added nvm use v17.9.0 in the last line
nvm alias default
ran nvm alias default v17.9.0
.nvmrc
added nvm use v17.9.0 in ~/.nvmrc
reload/re-launch vscode
reload vscode and/or quit vscode then restart vscode.
check in the terminal
check if nvm working by checking its version on the newly opened vscode instance terminal.
$ nvm current
v17.9.0
$ node -v
v17.9.0
re-try the debug
the same. wow.
/home/user/.nvm/versions/node/v13.10.1/bin/node npx webpack serve --config config/webpack.config.dev.js --port 3051
Process exited with code 1
What tf is going on with vscode? What am I missing here, may I know? Thanks.

I have checked and found out my vscode is reflecting the same version I am changing from the terminal outside the vscode terminal. SO it's working for me let's try some steps for you to fix this problem:
Restart the vscode (which you have already tried). Also restart the pc and check.
Uninstall the older version of node i.e. v13.10.1 if you are not using it again.
Last option is to uninstall vscode and install the latest version of vscode if possible.
There are lots of this kind of scenerios when vscode terminal don't reflect the changes but it gets fixed by just restarting the terminal again in vscode which is not happening in your case.
But I hope these 3 steps will help you to get it fixed.

Related

How to use zsh shell when debugging in VS Code

I run different node versions to build different web apps on my machine. I use nvm to manage the environments.
I set the integrated terminal in VS Code for osx to zsh as so:
"terminal.integrated.shell.osx": "/bin/zsh",
In the integrated terminal It appears to be running zsh, my nvm config runs etc.
But when I run the VS Code Debugger it doesn't pick up my nvm version.
When I run echo $SHELL in the integrated terminal I get /bin/bash even though it appears to be running /bin/zsh. In iTerm2 i get /bin/zsh as expected.
I need the debugger to run in zsh so that the nvm config is picked up and the build step is run in the correct node version. Otherwise node-sass has a fit etc and my debugging environment is out of whack with dev and prod.
How can I get the VS Code dubugger to run in zsh?
BTW: I am using the chrome debugger extension which appears to disallow the out-the-box node version debugger config such as "runtimeVersion": "9.4.0".
Add next to your settings.json, respecting your OS.
This covers both normal and debug terminals
"terminal.integrated.profiles.osx": {
"zsh": {
"path": "zsh",
"args": []
}
},
"terminal.integrated.defaultProfile.osx": "zsh"

Activate conda environment stopped working in vscode

I have noticed that conda activate environment stopped working in vscode integrated terminal with no obvious reason (I certainly did not install any new extensions, nor updated conda or vscode in the last few days).
Expected behaviour
After running conda activate environment I want the environment to be activated and be capable of using the environment python interpreter. Essentially it should look like this:
(base) lpravda-ml:~ lpravda$ conda activate rdkit-env
(rdkit-env) lpravda-ml:~ lpravda$ which python
/Users/lpravda/anaconda3/envs/rdkit-env/bin/python
This is what I can achieve using non-vscode terminal and work with conda as usual.
Actual behaviour
This happens when I type in the same set of commands in vscode integrated terminal:
(base) lpravda-ml:~ lpravda$ conda activate rdkit-env
(rdkit-env) lpravda-ml:~ lpravda$ which python
/usr/local/bin/python
The environment seems to be switched on, however python still points to the system install python 2.7 and I have no idea why.
It used to be working like for years and now it broke down.
Note: When I run debugger in vscode the correct conda environment is selected and executed.
My setup:
OS: Mac OS X: 10.14.3
vscode: 1.31.1
conda: 4.6.7
Update
ongoing issue with the following update:
OS: Mac OS X: 10.14.3
vscode: 1.33.3
conda: 4.6.8
Any idea what could possibly broke down?
it is issue which you can read about it here, but I find this solution
which solve the issue in this version. Also, as community said the problem with python interpreter and env gonna fix in next major update.
Create an workspace folder
Inside the create file post the following code:
{
"folders": [
{
"path": "."
}
],
"settings": {
"python.condaPath": "/home/pcuser/anaconda3/condabin/conda",
"python.pythonPath": "/home/pcuser/anaconda3/envs/my_env/bin/python",
"python.terminal.activateEnvironment": true,
"python.terminal.activateEnvInCurrentTerminal": true,
}
}
Save configuration and close vscode
Open vscode.
It will select automatically the conda enviroment (Should appear at the bottom left of vscode). Inside terminal 'my_env' will also be selected. If vscode doesn't select the 'Python Selected Interpreter' before you open the terminal the my_env inside terminal won't be selected. Open the terminal after the my_env is selected by vscode

VS Code opens a new debug console every time I build/run

Every time I build or run a program in VSCode a new python debug console is loaded. Before I know it I have 20+ and need to start deleting them. After 32 open consoles I get the error "The terminal process terminated with exit code: 256". I changed the terminal from the default console to git bash recently. How can I stop this?
A way around this issue is to stop VS Code from redundantly printing to the TERMINAL during debugging in the first place. Since it prints to the DEBUG CONSOLE as well, you can use that instead.
Change console to "none" "internalConsole" in each configuration in your project's launch.json file:
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "internalConsole"
}
]
May 2019 Update: the "none" option was replaced by "internalConsole" so I edited my answer to reflect that. Here's the relevant GitHub Issue.
Adding "args": ["&&", "exit"], to launch.json remedies this for Git Bash. Certainly a hack, but I no longer have to manually close many debug terminals.
This may have been resolved in recent debug updates to core VS Code within the last year (as of 8/2022), but I was still seeing this intermittently.
I don't know if this will help the original poster, but I discovered that for me the issue persisted due to using Git Bash as the default terminal in Windows. Switching to Command Prompt as the default terminal fixed the issue. I haven't tested with other platforms or terminals.
Changing the default terminal to Command Prompt causes the Python extension to launch the "Python Debug" terminal with Command Prompt instead of Git Bash. I did log a VS Code/Python Extension defect about this. The initial response is that Git Bash is not officially supported currently.
There appears to be a communication problem between the Git Bash terminals and VS Code that causes this issue. Some of the characters between Git Bash and VS Code get dropped. Sometimes this mangles the debug command and I get and error and have to retry in addition to getting an extra debug window.
There is some additional background info and hacks to fix this from the past in this answer.
Hopefully fixed in the Insiders Build and should be in v1.54. See Debug opens a new integrated terminal for each Python session
. Test it in the Insiders Build if you can and report at the issue if it fixed/did not fix.
Actually you can delete all the instances of the terminal just by clicking on the trash can icon 🗑. If it does not work for the first time, restart the VS Code and try again.

Integrated terminal setup for msys mingw not working for build task

I have managed to get the integrated terminal working with msys (bash) terminal using the following settings:
"terminal.integrated.shell.windows": "C:\\msys64\\bin\\msys_shell.cmd",
"terminal.integrated.shellargs.windows": "-mingw64 -defterm -nostart",
"terminal.integrated.env.windows": "HOME": "${workspace Folder}"
And this works well. I had to add the env "HOME" entry to get the sh to start in the correct home directory as it wouldn't work with (or with nothing at all):
"terminal.integrated.cwd": "${workspaceFolder}"
Now I have run into another problem. While the above settings work perfectly for a terminal window they fail for the build task. So I am forced to manually "make" from the integrated terminal window.
It fails with with error:
/d: /d: is a directory
My environment is Windows 10 msys64 mingw64.
Any ideas appreciated!
I ran into the same issue today. On their help page for tasks.json they talk about the options fields in the settings.
VSCode uses the default shell for tasks unless you tell it not to. Additionally you'll have to pass your command to the resulting shell. I solved that using -shell bash -c so bash runs the command immediately.
The syntax is something like this:
"command": "make -j8",
"options": {
"shell": {
"executable": "C:\\msys2\\msys2_shell.cmd",
"args": ["-defterm", "-mingw64", "-no-start", "-here", "-shell bash -c"]
}
}

I can't run nodemon from Integrated Terminal of Visual Studio Code Mac OS

I have installed nodemon by: sudo npm install -g nodemon. With MacOS Terminal, i can run nodemon command.
But in Integrated Terminal of Visual Studio Code, I can't run nodemon and I don't know why.
Maybe two terminals don't sync ?
Help me, please.
In my case
changed the default shell from Powershell to CMD
restart VSCode.
VSCode now started with cmd chosen as the default, and the problem didn't happen with cmd.
Shutdown VS Code and launch it again from the command line with 'code .'.
Above approach should fix the issue. Sometime when we install node after installing visual studio some sort of environment variable path issue happens.
Looks like this has been asked by others. But here is a possible solution. In you package.json edit scripts:
"scripts": {
"serve": "nodemon server.js"
},
then npm run serve
You can also check you bash profile
if nodemon is not being found by bash.
~/.bash_profile
add
PATH=$PATH:/usr/local/bin/bin/
Check this solution
and this discussion here
I was also facing a similar problem for a long time during my web development. If you are also facing these problem in VS code, so I recommend you to install Powershell Extention in your vs code or update your Powershell Extention. And restart your vs code.