18

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.

6 Answers 6

43

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

10
  • 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 9, 2020 at 14:25
  • 4
    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. Dec 23, 2020 at 4:29
  • 1
    Excellent. Fixed the exact same issue for me as well :)
    – mspoulsen
    Jan 5, 2021 at 22:40
  • 3
    This worked for me on fresh Ubuntu (20.04). FYI, just to re-affirm, preferences related to this are in Preferences/Features/Terminal.
    – Kalnode
    Feb 27, 2021 at 18:53
  • 2
    Great! This has worked for me but curious to know why -i is needed Oct 20, 2021 at 12:38
18

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

4
  • Open Settings (cmd + ,). Search for Osx. Click where it says edit in setting.json.
    – Resonance
    Sep 23, 2022 at 22:34
  • Setting the defaultProfile ("terminal.integrated.defaultProfile.linux": "bash" in my env) fixed all my issues. Good one thanks 👍 Feb 13, 2023 at 13:37
  • Holy cow, 5 hours and 20 threads later, this worked for me.
    – Kalnode
    Aug 19, 2023 at 13:48
  • Thank You so much for sharing this! I checked few different solutions before and they didn't work for me, but this one really helped! What I've changed though is the "structure" and "path": "terminal.integrated.automationProfile.linux": { "path": "bash", "args": [ "-i" ] }. Glory and thanks to the One! Bless!
    – kcpr
    Aug 29, 2023 at 10:21
13

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"]
    }
  },
1
  • Doesn't work for me, still getting npm command not found. Why is this needed anyway, is there a ticket for this? Seems kind of wild this isn't working out of the box.
    – E. K.
    Nov 6, 2022 at 22:14
5

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

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.

0

This can also be caused by installing the unofficial vscode snap package. Since the app is contained it does not have access to npm.

For reference:

https://github.com/flathub/com.visualstudio.code#readme

It's especially easy to install the snap package by mistake on Ubuntu. To fix the issue: uninstall the snap version and install the "non snap" official version.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.