/usr/bin/env: ‘node’: 运行 vscode 任务时没有这样的文件或目录 [英] /usr/bin/env: ‘node’: No such file or directory when running vscode task

查看:30
本文介绍了/usr/bin/env: ‘node’: 运行 vscode 任务时没有这样的文件或目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I have a basic task setup to build my TypeScript and Sass files. It looks like this:

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Gulp Build",
      "group": "build",
      "command": "./node_modules/.bin/gulp",
      "type": "shell",
      "args": [
        "build"
      ],
      "problemMatcher": []
    }
  ]
}

When I press Ctrl+Shift+B to select a build task, I select the one above and in my terminal I get this:

> Executing task: ./node_modules/.bin/gulp build <

/usr/bin/env: ‘node’: No such file or directory
The terminal process terminated with exit code: 127

I have exported the variables:

.gnomerc and .bashrc:

export PATH="$NVM_BIN:$NPM_HOME:$PATH"

Note: Both Node and NPM were both installed using NVM

If I open the editor from my Favorites or through Activities, I get the above error. If I open from the command line, it works fine. How can I get this working without having to open from the command line every time?

解决方案

This happens because .bashrc is not loaded for tasks, as they are non-interactive shells. You need to have the nvm shell enhancements loaded for non-interactive shells as well to use global packages installed via nvm to be available to VS Code.

Create a new text file named, say, nvm-autoload.sh and place it inside /etc/profile.d/ folder to run it for all login shells, which includes the task shells for VS Code. Add the following to that file:

# Enable nvm if available
if [ -f ~/.nvm/nvm.sh ]; then
  source ~/.nvm/nvm.sh
fi

You may need to logout and log back in for this to take effect.

这篇关于/usr/bin/env: ‘node’: 运行 vscode 任务时没有这样的文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆