问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/52131394/usr-bin-env-node-no-such-file-or-directory-when-running-vscode-task