9

After creating a cloud function addMessage on Firebase using Firebase SDK 4.12.0, the following code does not work when attempting to call the addMessage function from within my client app:

var firebase = require("../node_modules/firebase")
var functions = firebase.functions();

functions.httpsCallable("addMessage").call(
    //...
)

TypeError: firebase.functions is not a function

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
B. Jack
  • 301
  • 2
  • 7

1 Answers1

21

The solution was to add require("firebase/functions")

B. Jack
  • 301
  • 2
  • 7
  • a "-" not / is seems const functions = require('firebase-functions'); – cfl Aug 31 '19 at 12:54
  • 3
    For those who are loading from CDN, include corresponding Firebase JS SDKs. For example, if firebase.functions() is undefined, then include `firebase-functions.js` from CDN as documented here https://firebase.google.com/docs/web/setup#libraries_CDN – udeep shrestha Nov 04 '19 at 03:11
  • 2
    If using ES6 use this: import 'firebase/functions' – Boy May 21 '20 at 21:34