This site uses cookies to analyse traffic, remember your preferences, and optimise your experience. Learn more, read the privacy policy page.

VSCode: NVM /bin/bash: npm: command not found

VSCode: NVM /bin/bash: npm: command not found

When you want to run a task but you get an adventure with bash

Putting the ubuntu system back together, I met a new problem I did not know. When I wanted to run the task in VSCode, but there was such a message in the console:

Screenshot with npm command error in VSCode

This should not happen because I had the node version manager already installed and downloaded the latest node with npm.
At the beginning I found out that this may be some error in the task, so I tried to run the script with node without npm, but unfortunately another error appeared:

Screenshot with node command error in VSCode

I started to guess that bash which is run on the task does not load the .bashrc startup file. I made a simple check by creating a task that displays the variable set in .bashrc. Nothing appeared so now it was sure that this is the reason why node and npm not running. When looking for a solution, I found the code in the .bashrc:

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;

The code above stops executing the rest of the code if bash does not start in interactive mode, so the node version manager has not been initialized. (It was added at the end of this file.)
The fastest solution is to force vscode to run tasks in this mode. After a few minutes of searching I found a field in the settings:

  "terminal.integrated.shellArgs.linux": [

Now the tasks start correctly and everything works again without any complaints. :)

Word count: 254

Want to know more and be immediately informed about new posts?

Let's stay in touch and leave your email:

Related posts: