15

I'm trying to run a task on window load in VSCode where a terminal opens and nvm use && yarn dev is run by default. However, running this shell tasks seems to not load my zsh profile.

The output I get from running my task is:

The terminal process "zsh '-c', 'nvm use && yarn dev'" terminated with exit code: 127.

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

But if I then manually start a new terminal and run the same command (ie: by pressing plus, opening a new integrated terminal), it will work as intended.

Suspecting that VSCode isn't loading my profile for some reason, I tried adding the following to my task, it resulted in the error /bin/zsh: can't open input file: nvm use && yarn dev The terminal process "zsh '-l', 'nvm use && yarn dev'" terminated with exit code: 127..

// in dev task
"options": {
  "shell": {
    "executable": "zsh",
    "args": ["-l"]
  }
},

.vscode/tasks.json

{
    "version": "2.0.0",
    "presentation": {
      "echo": false,
      "reveal": "always",
      "focus": false,
      "panel": "dedicated",
      "showReuseMessage": true
    },
    "tasks": [
      {
        "label": "Create terminals",
        "dependsOn": [
          "Dev",
        ],
        // Mark as the default build task so cmd/ctrl+shift+b will create them
        "group": {
          "kind": "build",
          "isDefault": true
        },
        // Try start the task on folder open
        "runOptions": {
          "runOn": "folderOpen"
        }
      },
      {
        "label": "Dev",
        "type": "shell",
        "command": 
          ["nvm use && yarn dev"],
        "isBackground": true,
        "problemMatcher": [],
        "presentation": {
          "group": "dev-group"
        }
      },
    ]
  }
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Alex McLean
  • 2,524
  • 5
  • 30
  • 53
  • 1
    I am also having the same problem and none of the answers resolve this. Opened a bug for this https://github.com/microsoft/vscode/issues/143061 – Vikrant Feb 14 '22 at 20:58

5 Answers5

20

This worked for me*:

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

*(add to your settings.json)

github.com/microsoft/vscode/issues/143061

Kostas Minaidis
  • 4,681
  • 3
  • 17
  • 25
Vikrant
  • 748
  • 5
  • 15
5

You may need to add an automation profile as well

  "terminal.integrated.profiles.osx": {
    "zsh": {
      "path": "/bin/zsh -l",
      "args": ["-l"]
    }
  },
  "terminal.integrated.automationProfile.osx": {
    "path": "/bin/zsh"
  }
Pbrain19
  • 1,975
  • 2
  • 14
  • 11
3

try adding this to your settings.json

  "terminal.integrated.profiles.osx": {
        [...]
        "zsh": {
            "path": "/bin/zsh -l",
            "args": [
                "-l"
            ]
        },
        [...]
  },

Note that the important part is

    "path": "/bin/zsh -l",

I had the same problem and I found that for some reason VScode does not take into consideration the -l flag passed in args. So you can just include it with path.

If you do not have terminal.integrated.profiles.osx in your settings, you can copy it from the default settings (open the Command Palette and search for 'default settings').

I did not need to do this, but you can make sure that zsh is the default terminal profile for VScode by setting terminal.integrated.defaultProfile.osx to zsh

mockingjay
  • 181
  • 1
  • 10
2

Try running echo $SHELL from VSCode's integrated terminal. If you're on a Mac or Linux machine, you can compare that output to the output from the terminal app (outside VSCode). It's possible your default shell in VSCode is set incorrectly or using a copy of zsh at another location. If so, set VSCode's default shell through the command palette (Terminal: Select Default Shell).

Also check out your shell's default profile (Terminal: Select Default Profile) from the command palette and make sure it's set to zsh -l... using the -c argument (non-login non-interactive) will prevent ~/.zshrc from being executed, which sounds like what's going on here given your error output.

Finally, confirm your profile is located correctly (at ~/.zshrc) and that both nvm and yarn PATHs are exported. Alternatively, if you're trying to reference yarn locally (if for some reason you only installed it locally), you'll need to run yarn via npx...

Tim
  • 2,843
  • 13
  • 25
  • 1
    My default shell works fine (via the integrated terminal). The only issue is when I'm trying to run the shell automatically from a VSCode task. – Alex McLean Feb 04 '22 at 16:07
2

via GUI you can do the following

Press command + , and search for terminal.integrated.showExitAlert than unselect thick like below > enter image description here

I hope that will not get minus points here...

mati kepa
  • 2,543
  • 19
  • 24