12

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.

AskYous
  • 3,740
  • 5
  • 40
  • 69

5 Answers5

34

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+?)

VirxEC
  • 849
  • 10
  • 21
  • 3
    This works for me after setting up a new Linux Mint computer. I'd love to know why I needed it on this one, but not on my last computer which had the same OS. I copied my VSCode settings over, so everything should be the same. – Jack Steam Jun 09 '20 at 14:25
  • 3
    I ran into this on macOS and used the above to fix it except I used terminal.integrated.shellArgs.osx instead of linux and it worked after restarting VSCode. – Joshua Dyck Dec 23 '20 at 04:29
  • 1
    Excellent. Fixed the exact same issue for me as well :) – mspoulsen Jan 05 '21 at 22:40
  • Switched from linux to osx, worked out pretty good, thanks! – Fabio Martins Feb 07 '21 at 15:08
  • 2
    This worked for me on fresh Ubuntu (20.04). FYI, just to re-affirm, preferences related to this are in `Preferences/Features/Terminal`. – MarsAndBack Feb 27 '21 at 18:53
  • Using VSCode Version: 1.60.1 and `terminal.integrated.shellArgs` is not a setting anymore. – Jason Kuhrt Sep 17 '21 at 15:31
  • 1
    Using https://code.visualstudio.com/docs/editor/integrated-terminal#_terminal-profiles worked for me though, where args can be set. – Jason Kuhrt Sep 17 '21 at 15:38
  • Great! This has worked for me but curious to know why `-i` is needed – Premkumar chalmeti Oct 20 '21 at 12:38
  • Hey @VirxEC , can you update the snippet to this: https://stackoverflow.com/a/70816845/1664811 ? I tried posting in the comment, but comments won't show multi-line snippets, and the edit queue on your answer is full. – AlenL Jan 22 '22 at 20:25
2

For versions where there is warning for VirxEC solution, can use

    "terminal.integrated.profiles.osx": {
        "zsh": {
            "path": "zsh",
            "args": [
                "-i"
            ]
        }
    },
    "terminal.integrated.defaultProfile.osx": "zsh",

from https://code.visualstudio.com/docs/editor/integrated-terminal#_terminal-profiles

tonisives
  • 1,386
  • 1
  • 12
  • 15
2

Update to @VirxEC's answer for newer versions of VSCode (1.60+ ?) the correct setting is (change the actual shell path/name as desired):

  "terminal.integrated.profiles.linux": {
    "bash": {
      "path": "bash",
      "icon": "terminal-bash",
      "args": ["-i"]
    }
  },
AlenL
  • 309
  • 1
  • 6
1

I found the solution. I had to tell nvm the default node version because I uninstalled a version before I had this error. See here: https://stackoverflow.com/a/34777308/1404347

AskYous
  • 3,740
  • 5
  • 40
  • 69
0

I had the same issue, though I was using zsh and nvm, but if you also happen to get this error at startup:

"Unable to resolve your shell environment in a reasonable time. Please review your shell configuration."

Then maybe this fix would work for you too.

Sameh
  • 68
  • 6