Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode tasks error: /bin/bash: npm: command not found

I've been using node and npm forever. Right now, however, when do command shift p, Tasks: Run task, npm build, I get this error message:

Executing task: npm install <

/bin/bash: npm: command not found The terminal process terminated with exit code: 127

Terminal will be reused by tasks, press any key to close it.

In the terminal, node and npm work fine. I even tried running /bin/bash; node -v and that works fine.

like image 651
AskYous Avatar asked Apr 23 '19 18:04

AskYous


People also ask

Why npm command is not working in VS code?

If you've installed npm globally on your system, and you're getting the error message from VSCode terminal, it might be the terminal that didn't update the VSCode application. Just close all VSCode windows and reopen the application again to reload all of its module – that should be enough to resolve the issue.

Why node is not working in VS code?

You must click the Kill Terminal button (highlighted) and then restart VS Code and node will start working again. Best on making a change of system environment variable Path is restarting Windows to make sure that really all processes make use of the modified Path variable.


1 Answers

Since this is the first result on Google, I want to share my solution despite this being a year old. The problem is that VS Code isn't initializing the NPM command, and many others when using VS Code Tasks. The solution to this is to force VS Code to do so.

This is a very simple thing to do. Simply open up settings.json and add this:

{
  "terminal.integrated.shellArgs.linux": [
    "-i"
  ]
}

I know that this thread is a year-old, but it's the first result I found on Google when going on my search, and while AskYous's solution worked for him, it didn't for me.

see comments for changes due to new versions of VSC (1.60.1+?)

like image 183
VirxEC Avatar answered Sep 19 '22 12:09

VirxEC