目次
はじめに
Cloud Functions for Firebase を試そうとしたらちょいちょいすんなりいかなかったので、メモを残します。
環境
macOS Catalina バージョン10.15.6
firebase init で失敗する
Firebaseプロジェクトが存在する状態で
$ firebase init firestore
とコマンドを打ったら以下のようなエラーが出ました
Error: Failed to get Firebase project YOUR_PROJECT_NAME. Please make sure the project exists and your account has permission to access it.
どうも前回ログインから時間が経っていると発生する場合があるらしいです。
以下のコマンドでログインしなおしたら正常に動作しました。
$ firebase logout
$ firebase login
firebase emulators:start で失敗する
以下のようなエラー文が出ました。
$ firebase emulators:start
i emulators: Starting emulators: functions, firestore, hosting
⚠ functions: The following emulators are not running, calls to these services from the Functions emulator will affect production: database, pubsub
✔ functions: Using node@14 from host.
i firestore: Firestore Emulator logging to firestore-debug.log
⚠ firestore: Fatal error occurred:
Firestore Emulator has exited with code: 1,
stopping all running emulators
i hub: Stopping emulator hub
i functions: Stopping Functions Emulator
i firestore: Stopping Firestore Emulator
⚠ firestore: Error stopping Firestore Emulator
Having trouble? Try firebase [command] --help
JDKが必要だとというプロンプトが出るし、firestore-debug.log
にもそのように書かれています。
Oracle のJDKダウンロードページ から落としてきてインストールしました。
Firebase のバージョンがインストールしたものと異なる
以下のように9.5.0を入れたと思ったのに。
$ npm i -g firebase-tools
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
/usr/local/opt/nvm/versions/node/v12.18.3/bin/firebase -> /usr/local/opt/nvm/versions/node/v12.18.3/lib/node_modules/firebase-tools/lib/bin/firebase.js
+ firebase-tools@9.5.0
updated 1 package in 30.88s
バージョン確認をすると8.7.0 が入っている。
$ firebase --version
8.7.0
以下のように解決しました。
参照しているfirebase を確認。
$ which firebase
/usr/local/bin/firebase
npm のグローバルディレクトリの確認。
$ npm bin -g
/usr/local/opt/nvm/versions/node/v12.18.3/bin
(not in PATH env variable)
想定とは異なるfirebase を参照していたようです。
ので、ローカルのfirebase を削除。
$ rm -rf /usr/local/bin/firebase
その上で以下のようにエイリアスをはる。
$ alias firebase="`npm config get prefix`/bin/firebase"
すると、想定通りのバージョンになりました。
$ firebase --version
9.5.0
$ which firebase
/usr/local/opt/nvm/versions/node/v12.18.3/bin/firebase
参考: stackoverflow
alias コマンドはマシンを再起動すると設定が消えると思うので、
より丁寧にするなら ~/.bash_profile
などで以下のようにパスを通します。
export PATH=$PATH:$(npm get prefix)/bin
で、source ~/.bash_profile
で変更を反映すればOK。
firebase deploy –only functions で失敗する
以下のようなエラーが出ました。
Error: HTTP Error: 403, Unknown Error
この場合も冒頭と同様、ログアウト・ログインで解消しました
$ firebase logout
$ firebase login
最後に
以上です。
お疲れ様でした!
Thanks for following my site; you are very kind.
いいねいいね
sure !
いいねいいね: 1人
Thank you.
いいねいいね