Visual Studio Code to use node version specified by NVM

后端 未结 17 1181
渐次进展
渐次进展 2020-12-07 16:01

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 (no

相关标签:
17条回答
  • 2020-12-07 16:42

    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".

    0 讨论(0)
  • 2020-12-07 16:43

    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
    
    0 讨论(0)
  • 2020-12-07 16:45

    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": []

    0 讨论(0)
  • 2020-12-07 16:46

    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.

    0 讨论(0)
  • 2020-12-07 16:49

    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
    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

    0 讨论(0)
  • 2020-12-07 16:50

    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.

    0 讨论(0)
提交回复
热议问题