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

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

问题描述

我有一个基本的任务设置来构建我的TypeScript和Sass文件.看起来像这样:

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": []
    }
  ]
}

当我按下 Ctrl + Shift + B 选择一个构建任务时,我选择了上面的一个,然后在终端中看到了:

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

>执行任务:./node_modules/.bin/gulp build<

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

/usr/bin/env:节点":没有这样的文件或目录
终端进程终止,退出代码为:127

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

我已经导出了变量:

.gnomerc .bashrc :

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

注意: NodeNPM均使用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?

推荐答案

之所以会发生这种情况,是因为未为任务加载.bashrc,因为它们是非交互式外壳.您还需要为非交互式shell加载nvm shell增强功能,以使用通过nvm安装的全局软件包,以供VS Code使用.

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.

创建一个名为nvm-autoload.sh的新文本文件,并将其放置在/etc/profile.d/文件夹中,以针对所有登录Shell(包括VS Code的任务Shell)运行该文件.将以下内容添加到该文件:

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:“节点":运行vscode任务时没有这样的文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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