Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 880 Vote(s) - 3.49 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Visual Studio Code to use node version specified by NVM

#11
Some of the answers provided are correct and upvoted, but somewhat incomplete. This procedure worked for me:

1. Open the terminal window ***inside* VS Code** and run `node -v`. You'll get for instance `v10.12.0`.
2. Open a terminal window ***outside* VS Code** Change your **node** version with **nvm** (ie. `nvm use v12.14.0`)
3. `Cmd`+ `Shift` + `p` and choose **Preferences > Open Settings (JSON)**
4. Add `"terminal.integrated.shellArgs.osx": []` to your user config
5. `Cmd`+ `Shift` + `p` and choose **Shell Command: Install 'code' command in PATH**
6. *Close **VS Code***.
7. Open a terminal window and run `code`. This will open **VS Code** with a new and updated `bash` / `zsh` session.
8. 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:

```bash
nvm alias default v12.14.0
```
Reply

#12
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:

```sh
# 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
```
Reply

#13
So, your nvm is configured well, but other version of node STILL keeps taking over?

Remove all non-nvm versions of node:

1. `brew uninstall --force node` (yarn will be fine without system node)
2. [Other version installed from pkg or other non-nvm method][1]
3. 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`


[1]:

[To see links please register here]

Reply

#14
None of the other solutions worked for me.

So I ran `nvm alias default node` and this fixed it for me.
Reply

#15
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`
```bash
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.
```text
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.
```bash
$ node -v
v12.19.1
```




Reply

#16
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:
1. Click the down arrow on the terminal dropdown
2. Select Default Shell
3. Select 'bash'
4. Try `node -v` and that should return the correct version that was set as default `nvm alias default v12.14.0`
Reply

#17
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!

```javascript
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit:

[To see links please register here]

"version": "0.2.0",
"configurations": [
{
"command": "nvm use && yarn start",
"name": "Launch",
"request": "launch",
"type": "node-terminal",
},
]
}
```
Reply

#18
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][1]


[1]:
Reply

#19
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][1] for explanation and [here][2] for old args way:


[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply

#20
```
sudo rm -rf /usr/local/opt/node@<YOUR_NODE_VERSION>
```
then restart the Visual Code
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through