Skip to content Skip to sidebar Skip to footer

How To Import Firebase-functions And Firebase-admin In Es6 Syntax For Transpiling With Babel For Node 10

I'm currently writing my cloud functions in ES6 and transpiling with Babel to target the Node v10 environment. And I've noticed something weird. Why is that when I import firebase-

Solution 1:

The reason why import functions from 'firebase-functions'; will not work is because 'firebase-functions' does not have a "functions" default export.

Hence, this error:

!  TypeError: Cannot read property 'https'ofundefined
    at Object.<anonymous> (C:\myProject\functions\index.js:28:55)

Answer :

The first option would be to import an entire module's contents and add functions into the current scope containing all the exports from the module firebase-functions.

import * as functions from'firebase-functions'

The second option would be to import a single export from a module, https in this case, since you are trying to read property https of 'firebase-functions'.

import { https } from'firebase-functions'

More information can be found here.

Hope this clarifies your question.

Post a Comment for "How To Import Firebase-functions And Firebase-admin In Es6 Syntax For Transpiling With Babel For Node 10"