Fish shell,nvm,告诉我 node 和 npm“当前未安装”,但它们

时间:2021-03-03 20:00:17

标签: node.js npm fish nvm macos-big-sur

在最近更新 OS X Big Sur 上的 fish、fisher、bass 和 nvm 之后,我在使用鱼壳时遇到了 npm 和 node 问题。

$ node -v

type: Invalid combination of options
Fish nvm: 'node' is currently not installed, try running npm i -g node

$ npm -v

type: Invalid combination of options
Fish nvm: 'npm' is currently not installed, try running npm i -g npm

NVM 似乎工作正常:

$ nvm 列表

->     v10.16.0
        v12.4.0
       v12.16.1
       v13.11.0
       v14.16.0
         system
default -> 10.16.0 (-> v10.16.0)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v14.16.0) (default)
stable -> 14.16 (-> v14.16.0) (default)
lts/* -> lts/fermium (-> v14.16.0)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.0 (-> N/A)
lts/erbium -> v12.21.0 (-> N/A)
lts/fermium -> v14.16.0

成功切换节点版本。

$ nvm 使用 v14 Now using node v14.16.0 (npm v6.14.11)

$哪个节点 /Users/brianfogel/.nvm/versions/node/v14.16.0/bin/node

$ which npm /Users/brianfogel/.nvm/versions/node/v14.16.0/bin/npm

这里有一些其他可能有助于展示的其他内容:

$fish --version fish, version 3.2.0

$fisher --version fisher, version 4.2.0

$ nvm -v 0.37.2

$ cat ~/.config/fish/functions/node.fish

function node -d "Server-side JavaScript runtime" -w node
  __nvm_run "node" $argv
end

$ cat ~/.config/fish/functions/npm.fish

function npm -d "node package manager" -w npm
  __nvm_run "npm" $argv
end

$ cat ~/.config/fish/functions/nvm.fish

function nvm
  if not type -q bass
    echo 'Bass is not installed please install it running fisher edc/bass'
    return
  end
  set -q NVM_DIR; or set -gx NVM_DIR ~/.nvm
  set -q nvm_prefix; or set -gx nvm_prefix $NVM_DIR
  
  bass source $nvm_prefix/nvm.sh --no-use ';' nvm $argv

  set bstatus $status

  if test $bstatus -gt 0
    return $bstatus
  end

  if test (count $argv) -lt 1
    return 0
  end

  if test $argv[1] = "use"; or test $argv[1] = "install"
    set -g NVM_HAS_RUN 1
  end
end

$ cat /usr/local/bin/node

#! /usr/bin/env fish
__nvm_run "node" $argv

$ cat /usr/local/bin/npm

#!/usr/bin/env fish
__nvm_run "npm" $argv

$ $ set --show fish_user_paths

$fish_user_paths: set in global scope, unexported, with 10 elements
$fish_user_paths[1]: |/Users/brianfogel/.pub-cache/bin|
$fish_user_paths[2]: |/Users/brianfogel/flutter/flutter/.pub-cache/bin|
$fish_user_paths[3]: |/Users/brianfogel/flutter/flutter/bin|
$fish_user_paths[4]: |/usr/local/sbin|
$fish_user_paths[5]: |/Applications/Postgres.app/Contents/Versions/latest/bin|
$fish_user_paths[6]: |/Users/brianfogel/.npm-global/bin|
$fish_user_paths[7]: |/usr/local/Cellar/php/7.3.4_1/bin|
$fish_user_paths[8]: |/usr/local/sbin|
$fish_user_paths[9]: |/Applications/Postgres.app/Contents/Versions/latest/bin|
$fish_user_paths[10]: |/Users/brianfogel/.yarn/bin|
$fish_user_paths: set in universal scope, unexported, with 4 elements
$fish_user_paths[1]: |/Users/brianfogel/.npm-global/bin|
$fish_user_paths[2]: |/usr/local/sbin|
$fish_user_paths[3]: |/Applications/Postgres.app/Contents/Versions/latest/bin|
$fish_user_paths[4]: |/Users/brianfogel/.yarn/bin|

0 个答案:

没有答案