LoginSignup
9
5

More than 5 years have passed since last update.

firebaseとfirebase-adminを一緒に使っているとfirebase側のメソッド呼び出しがエラーになる

Posted at

エラー内容

CloudFunctionsを実行した際、firebase側のメソッドを呼び出した際に下記のエラーが出ていた
TypeError: firebase.auth is not a function

実行環境

package.json
  "dependencies": {
    "firebase": "^5.11.0",
    "firebase-admin": "^6.5.1",
  }

注)そもそも併用しているのはCloudFunctions側でメールパスワードをauthに登録しようとしたところ、firebase-adminにcreateUserWithEmailAndPasswordが無かったため

原因

firebaseとfirebase-adminは共有のモジュールを使っているが、その依存関係がおかしくなると起こるらしい。
firebase⇒firebase-adminの順にinstallするのが正しいとのこと。
https://github.com/firebase/firebase-js-sdk/issues/752

解決法

自分の場合、下記で解決

  1. 配下のnode_modulesディレクトリ、package-lock.jsonを削除
  2. 下記コマンドを実施
npm install firebase --save
npm install firebase-admin --save
9
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
5