Guide to importing firebase-functions and firebase-admin using ES6 syntax for transpilation with Babel in Node 10

I've been working on my cloud functions in ES6 and using Babel to transpile them for the Node v10 environment. But, I've come across an odd issue.

It seems that when I import firebase-functions like this:

import functions from 'firebase-functions';

An error occurs:

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

To resolve the error, I have to import it in a different way:

import * as functions from 'firebase-functions';

Interestingly, the same type of import works perfectly fine for firebase-admin:

import admin from 'firebase-admin';

QUERY

The main question here is:

Why does the following cause the issue with firebase-functions:

import functions from 'firebase-functions';            // DOESN'T WORK
import * as functions from 'firebase-functions';       // WORKS
import admin from 'firebase-admin';                    // WORKS

Answer №1

The issue with the code

import functions from 'firebase-functions';
is that the module 'firebase-functions' does not have a default export named "functions".

This results in the following error:

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

Resolution:

The primary solution is to import all contents of the module and include functions in the scope along with all exports from the module firebase-functions.

import * as functions from 'firebase-functions'

Alternatively, you can choose to import a specific export from the module, such as https, since you are trying to access the property https from 'firebase-functions'.

import { https } from 'firebase-functions'

For further details, refer to the information provided here.

I hope this explanation helps address your query.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What occurs when Click events are triggered on an <object> element?

I have set up a div, and inside that container, I embedded an SVG image using object (which I plan to manipulate later...). <div id="click-me"> some random Text <object data="some.svg" /> </div> Next, I added event listeners for t ...

What methods can I use to integrate a Google HeatMap into the GoogleMap object in the Angular AGM library?

I am trying to fetch the googleMap object in agm and utilize it to create a HeatMapLayer in my project. However, the following code is not functioning as expected: declare var google: any; @Directive({ selector: 'my-comp', }) export class MyC ...

Loading a Vue.js template dynamically post fetching data from Firebase storage

Currently, I am facing an issue with retrieving links for PDFs from my Firebase storage and binding them to specific lists. The problem arises because the template is loaded before the links are fetched, resulting in the href attribute of the list remainin ...

The free version of Neo4j and Linkurious for the community

Is it possible to integrate linkurious.js community edition with Neo4j? I have heard about the sigma-parser-cypher plugin. As a beginner in both Neo4j and Linkurious, your patience is appreciated. Can both Linkurious JS and Neo4j be run on the same machi ...

"Enhance Your Website with qTip2 Feature to Load Multiple AJAX Sites Simult

I'm currently utilizing the qTip2 library for my project and I've implemented their AJAX retrieval functions following this example: http://jsfiddle.net/L6yq3/1861/. To enhance my query, I have modified their HTML to include multiple links. The ...

Display a JSON object on a web browser

I am trying to display a JSON object on a web browser using HTML. The object is already in a text file and has been properly formatted for readability. My goal is to maintain the same formatting when displaying it on the browser. ...

Learn how to showcase a text file uploaded to a webpage with NODE js and HTML

<!DOCTYPE html> <html> <body> <form action = "/submit" method = "post"> Select a file: <input type="file" name="file"> <input type="submit"> </form> </bod ...

Utilizing Vue and Vuex to execute Axios operations within a store module

Currently, I am developing an application in Vue that utilizes Vuex for state management. For CRUD operations on the data, I have implemented Axios. The issue arises when, for example... I make a POST request to my MongoDB database through an Express ...

Delaying the activation of the code until the image upload is complete

I'm having trouble synchronizing code to upload an image using a vue composable, wait for the upload to finish, and then store the Firebase storage URL into a database. Despite getting the URL, the success code fires before the upload is complete. My ...

Is it possible to import data into a script?

When working with Angular, I am attempting to: $scope.data = "<script> alert('hi'); </script>"; Unfortunately, this approach does not seem to be effective. I also experimented with adding ng-bind-html but did not achieve any success ...

Unspecified origins of Js in Chrome Extension

console.log(chrome.runtime.sendMessage({from:"script2",message:"hello!"})); However, attempting to send the message from a background script to a content script is proving to be unsuccessful. https://i.stack.imgur.com/ERgJB.png ...

What is the best way to utilize an environmental variable for storing a database password within a Node.js environment

My attempt to conceal my database password using a .env file is failing. The compiler seems unable to locate the password. You can observe the environmental variable, PWD, designated for the database password in the .env file. PWD = 0000 SECRET = mySecre ...

unit test for mocha failing inside of a callback

I have been facing challenges while attempting to define my mocha tests in JSON format, parsing them, and then executing the tests. Specifically, I am struggling with running the tests within callback functions. function addTwoNumbers(a,b){ return a+b; ...

The 'Alias[]' type does not share any properties with the 'Alias' type

I encountered an issue: The error message 'Type 'Alias[]' has no properties in common with type 'Alias'' appeared. Here is my Alias setup: alias: Alias = { id: 0, domain_id: 0, source: '', dest ...

Transferring $scope information to resolve in $stateProvider.state

In the app.teams.show parent state, "team" is stored in $scope.data.team. From within a controller, I can access $scope.data.team and thus $scope.data.team.organization_id. The question is: How can I retrieve $scope.data.team.organization_id from inside t ...

What is the best way to instantiate objects, arrays, and object-arrays in an Angular service class?

How can I nest an object within another object and then include it in an array of objects inside an Angular service class? I need to enable two-way binding in my form, so I must pass a variable from the service class to the HTML template. trainer.service. ...

Default modal overlay closure malfunctioning; encountering errors when manually managed through jQuery

A custom overlay has been designed and implemented. <div class="overlay modal" id="11"> <div class="background-overlay"></div> <div class="description"> <div class="hidden-xs"> <img src=' ...

What is the best way to organize a flatlist for rendering?

I'm struggling with separating some flat-lists into different components. How can I arrange the rendering of the flat-list like the sample form (Picture "Sample UI")? I've tried, but it's not working correctly as it renders flat list A first ...

What is the best way to handle query string parameters when routing in Next.js?

One of the challenges I am facing is related to a URL structure like this: bar?id=foo When I navigate to this URL using router.push('bar?id=foo'), everything works perfectly. However, if I directly access the route in the browser, the query st ...

Deleting a file directory in Pyrebase storage without using a token: a step-by-step guide

I am currently developing an app that utilizes Firebase and Pyrebase as a wrapper. In the documentation, I noticed that the delete function requires a userIdToken parameter like this: storage.delete("images/example.jpg", user["idToken"]) Since my app does ...