[英]Why I have this error using ng serve in zsh terminal in vscode inside an angular project
Reading this I found that it is possible to use zsh inside VSCode so I configured these inside settings.json for my user:阅读本文后,我发现可以在 VSCode 中使用 zsh,因此我在settings.json 中为我的用户配置了这些:
"terminal.integrated.shell.linux": "/usr/bin/zsh",
"terminal.integrated.fontFamily": "'SauceCodePro Nerd Font Mono','Source Code Pro'",
"terminal.integrated.fontSize": 14,
But when I tried to start my Angular app ng serve
, it shows:但是当我尝试启动我的 Angular 应用程序
ng serve
,它显示:
zsh: command not found: ng
So following this response that had a similiar issue I added this to the .zshrc file:因此,按照这个有类似问题的回复,我将其添加到.zshrc文件中:
if [[ -s '/etc/zsh_command_not_found' ]]; then
source '/etc/zsh_command_not_found'
fi
But now it shows this, and I am not sure that it is the right package to install:但是现在它显示了这一点,我不确定它是否是要安装的正确软件包:
➜ ng serve
No se ha encontrado la orden «ng», pero se puede instalar con:
sudo apt install ng-common
What I can do?我可以做什么? Because with bash it works fine.
因为使用 bash 它可以正常工作。
I found out that I was missing loading nvm in the zshrc file.我发现我没有在 zshrc 文件中加载nvm 。 So I added this to the .zshrc file:
所以我将它添加到 .zshrc 文件中:
export NVM_DIR="/home/espe/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
Then I thought someone should have faced this before, and here is an article about how to solve this problem .然后我想之前应该有人遇到过这个问题,这里有一篇关于如何解决这个问题的文章。 So the previous code became this:
所以之前的代码变成了这样:
# lazyload nvm
# all props goes to http://broken-by.me/lazy-load-nvm/
# grabbed from reddit @ https://www.reddit.com/r/node/comments/4tg5jg/lazy_load_nvm_for_faster_shell_start/
lazynvm() {
unset -f nvm node npm npx 2>/dev/null
export NVM_DIR=~/.nvm
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
if [ -f "$NVM_DIR/bash_completion" ]; then
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
fi
}
nvm() {
lazynvm
nvm $@
}
node() {
lazynvm
node $@
}
npm() {
lazynvm
npm $@
}
npx() {
lazynvm
npx $@
}
# Add every binary that requires nvm, npm or node to run to an array of node globals
NODE_GLOBALS=(`find ~/.nvm/versions/node -maxdepth 3 -type l -wholename '*/bin/*' | xargs -n1 basename | sort | uniq`)
for cmd in "${NODE_GLOBALS[@]}"; do
eval "${cmd}(){ unset -f ${NODE_GLOBALS} 2>/dev/null; lazynvm; ${cmd} \$@ }"
done
Also, thanks to scttcper , for the improved solution.另外,感谢scttcper改进的解决方案。
Source:来源:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.