先说问题,答案放在后面
自从上次升级node后,每次vscode打开终端都会报
npm warn cli npm v10.8.2 does not support Node.js v18.14.2. This version of npm supports the following node versions: `^18.17.0 || >=20.5.0`. You can find the latest version at https://nodejs.org/. nvm is not compatible with the npm config "prefix" option: currently set to "/usr/local" Run `npm config delete prefix` or `nvm use --delete-prefix v18.14.2 --silent` to unset it.
执行node命令就报command not found: node
虽然我执行nvm use --delete-prefix v18.14.2 --silent之后好了,但下次打开vscode的终端,又会报上面的错误
并且Mac的终端是正常的,就vscode的终端会报上面的错误
翻阅了很多文章说要改.zshrc里的环境变量,然后 source ~/.zshrc。但是看了我的环境变量应该没问题。
.zshrc文件如下:
# Add RVM to PATH for scripting. Make sure this is the last PATH variable change. export PATH="$PATH:$HOME/.rvm/bin" # nvm config export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm export NVM_NODEJS_ORG_MIRROR=https://npmmirror.com/mirrors/node # pnpm export PNPM_HOME="/Users/zhanglinfeng/Library/pnpm" export PATH="$PNPM_HOME:$PATH" # pnpm endexport HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles
.profile文件如下
# Add RVM to PATH for scripting. Make sure this is the last PATH variable change. export PATH="$PATH:$HOME/.rvm/bin" [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
.bashrc文件如下
# Add RVM to PATH for scripting. Make sure this is the last PATH variable change. export PATH="$PATH:$HOME/.rvm/bin" export NVM_DIR="$HOME/.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 # pnpm export PNPM_HOME="/Users/zhanglinfeng/Library/pnpm" export PATH="$PNPM_HOME:$PATH" # pnpm end alias python2='/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7' alias python3='/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6' alias python=python3 # nvm config export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm export NVM_NODEJS_ORG_MIRROR=https://npmmirror.com/mirrors/node
.bash_profile文件如下
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin # Setting PATH for Python 3.6 # The original version is saved in .bash_profile.pysave PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}" export PATH [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function* source ~/.profile export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm export GEM_HOME=$HOME/Software/ruby export PATH=$PATH:$HOME/Software/ruby/bin # Setting PATH for Python 2.7 # The original version is saved in .bash_profile.pysave PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}" export PATH
后来找到一个靠谱回答是这样的
sudo rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/{npm*,node*,man1/node*}
system 版本应该是使用 brew 安装之后产生的。在终端里执行下面的命令,重启 vscode 后,我的可以了。
标签:node,vscode,Mac,export,HOME,PATH,nvm,NVM,DIR From: https://www.cnblogs.com/zhanglinfeng/p/18427743