5

When running an NPM script from the script explorer, it uses NVM's default version of node. Instead, I'd like to use the version dictated by .nvmrc. Is that possible?

1

2 Answers 2

0

There are several extensions that run nvm use on each terminal opened if an .nvmrc file is found in the workspace. These work for the NPM Script Explorer too.

The most downloaded one is called vsc-nvm.

In case it does not work out of the box, note that it runs nvm use in a /bin/sh shell, therefore you need to make sure nvm is accessible and works as intended from within sh.

P.S. This sounds like a good feature to add to the NPM Script Explorer itself, but as far as I can see, nobody suggested it yet.

Sign up to request clarification or add additional context in comments.

Comments

0

This works form me in linux.

Prerequisites

  • have nvm installed

  • have a .nvmrc file with the project's Node version placed in the root folder of your project

In your VS Code settings.json file, add these definitions

"terminal.integrated.profiles.linux": {
    "NvmBash": {
        "path": "bash",
        "source": "bash",
        "extensionIdentifier": "linux",
        "args": [
            "-c",
            "[ -f .nvmrc ] && { source ~/.nvm/nvm.sh; nvm use $(cat .nvmrc) || nvm install $(cat .nvmrc); } || true; exec $@"
        ]
    }
},
"terminal.integrated.defaultProfile.linux": "NvmBash"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.