Closed5
Flutter Firebaseを使おうとした際に、globalインストールしたnpmパッケージにPATHを通す方法が分からず試行錯誤した。
検証
環境構築。
firebase
へのPATHが通っておらず、Flutterfireが実行できない。
$ flutterfire configure
i Found 0 Firebase projects.
FirebaseCommandException: An error occured on the Firebase CLI when attempting to run a command.
COMMAND: firebase --version
ERROR: The FlutterFire CLI currently requires the official Firebase CLI to also be installed, see https://firebase.google.com/docs/cli#install_the_firebase_cli for how to install it.
npmの実行可能ファイルの場所はnpm bin
コマンドで確認可能。
npmで実行可能ファイルがGlobalインストールされる場所は$HOME/.npm-global/bin
とのこと。
$ npm bin -g
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
/Users/wakatsuki.ryuta/.npm-global/bin
参考:
$HOME/.npm-global/bin
のPATHを通したら実行可能になった。
$ export PATH=$PATH:$HOME/.npm-global/bin
$ firebase --version
11.22.0
Globalインストールされたnpmパッケージは{prefix}/lib/node_modules
にインストールされ、実行可能ファイル(bin files)は{prefix}/bin
にリンクされる。
Operates in "global" mode, so that packages are installed into the prefix folder instead of the current working directory. See folders for more on the differences in behavior.
- packages are installed into the {prefix}/lib/node_modules folder, instead of the current working directory.
- bin files are linked to {prefix}/bin
結論として次のコマンドを実行すればOK。
export PATH=$PATH:`npm prefix --location=global`/bin
npm bin
コマンドだとPATHが通っていない場合に必ずwarningがプリントされるため見た目によろしくない。
$ export PATH=$PATH:`npm bin --location=global`
npm ERR! bin (not in PATH env variable)
ブログ化した。
このスクラップは2023/02/02にクローズされました