Firebase-js-sdk: firebase.functions().httpsCallable() - new Headers() == undefined

Created on 16 Apr 2018  路  11Comments  路  Source: firebase/firebase-js-sdk

[REQUIRED] Describe your environment

  • Operating System version: MacOS 10.3.3
  • Firebase SDK version: "firebase": "^4.12.1"
  • Firebase Product: Cloud Functions

[REQUIRED] Describe the problem

Steps to reproduce:

Deploy a "functions.https.onCall" to Cloud Functions and try to make a call to it from a completely different Nodejs app (obviously with the correct credentials ie the same login etc).

Relevant Code:

I have a cloud function deployed. I'm then trying to call it like this from a completely separate Nodejs app:

var Firebase = require("firebase");
require("firebase/functions");

Firebase.initializeApp(require("../../../config/firebase-config.json"));
var Functions = Firebase.functions();

...

var sendPushNotification = Functions.httpsCallable("sendPushNotification");

sendPushNotification({
    user_id: params.user_id,
    obj: params.payload
})
.then(function(result) {
    console.log("Inside sendPushNotification success: " + JSON.stringify(result));
})
.catch(function(err) {
    console.log("Inside sendPushNotification error: " + err);
    console.log("Inside sendPushNotification error: " + JSON.stringify(err));
})
.finally(resolve);

I get the following error inside of the catch clause:

message:"Headers is not defined"

stack:"ReferenceError: Headers is not defined\n    at Service.<anonymous> (/Users/jayy/Programming/Projects/Node/Core_API/node_modules/@firebase/functions/dist/cjs/src/api/service.js:135:39)\n    at step (/Users/jayy/Programming/Projects/Node/Core_API/node_modules/tslib/tslib.js:133:27)\n    at Object.f [as next] (/Users/jayy/Programming/Projects/Node/Core_API/node_modules/tslib/tslib.js:114:57)\n    at __awaiter (/Users/jayy/Programming/Projects/Node/Core_API/node_modules/tslib/tslib.js:107:75)\n    at Object.__awaiter (/Users/jayy/Programming/Projects/Node/Core_API/node_modules/tslib/tslib.js:103:16)\n    at Service.call (/Users/jayy/Programming/Projects/Node/Core_API/node_modules/@firebase/functions/dist/cjs/src/api/service.js:126:24)\n    at callable (/Users/jayy/Programming/Projects/Node/Core_API/node_modules/@firebase/functions/dist/cjs/src/api/service.js:61:26)\n    at exports.send (/Users/jayy/Programming/Projects/Node/Core_API/lib/shared/push/core.js:46:9)\n    at Pro...

I looked at this file /node_modules/@firebase/functions/dist/cjs/src/api/service.js:135:39 and the issue seems to be with headers = new Headers();. That line of code can't be evaluated because the Headers class doesn't seem to exist in my project.

Any ideas why that may be? Am I missing something or may this is actually an issue with the latest version of the npm package? (I haven't tried any other version yet).

needs-triage

All 11 comments

Hey there! I couldn't figure out what this issue is about, so I've labeled it for a human to triage. Hang tight.

Hey @jyounus, can you reproduce this testing against the NPM tag firebase@next?

Hey @jshcrowthe, I had already refactored my code to use it via http instead, but reverted the changes to test what you suggested. Using the npm tag you suggested fixed the issue. It calls the cloud function now without any issues!

Is there currently an ETA on when the changes for firebase@next will be considered stable and "officially" released?

(I will close this issue now, thanks a lot!)

That is the next staged release that should go out later this week. Thanks for your help!

may i ask that what is the version offirebase@next by the time the issue was still active since i am facing same problem using 4.12.1.

Hello ! Thanks for creating this page. But I still having this issue. Using
"firebase-admin": "~5.12.0", "firebase-functions": "^1.0.1"
and
"firebase": "^5.0.4",

I'm seeing this issue as well

Same issue here.

   "firebase": "^5.9.4",
    "firebase-admin": "^7.2.0",
    "firebase-functions": "^2.2.1",

Is there a workaround?

        const config = {
            apiKey: process.env.REACT_APP_FIREBASE_KEY,
            authDomain: process.env.REACT_APP_FIREBASE_DOMAIN,
            databaseURL: process.env.REACT_APP_FIREBASE_DATABASE,
            projectId: process.env.REACT_APP_FIREBASE_PROJECT_ID,
            storageBucket: process.env.REACT_APP_FIREBASE_STORAGE_BUCKET,
            messagingSenderId: process.env.REACT_APP_FIREBASE_SENDER_ID
        };

        firebase.initializeApp(config);

        const getJobDeets = firebase.functions().httpsCallable('getJobDetails');

        getJobDeets({ jobId: "53d08a3a-8a39-4bc3-ac9e-8fbb6ec24910"}).then(result => {
          ...
        })

(node:82729) UnhandledPromiseRejectionWarning: ReferenceError: Headers is not defined at Service.<anonymous> (/Users/..../Development/.../.../src/..../node_modules/@firebase/functions/dist/index.node.cjs.js:493:25) at step (/Users/jttaynton/Development/.../..../src/../node_modules/tslib/tslib.js:133:27) at Object.next (/Users/jttaynton/Development/.../.../src/.../node_modules/tslib/tslib.js:114:57)

Same issue here, but only when calling from Google App Engine.

All I can find is that Headers is supposed to be included as a global by isomorphic-fetch. For some reason this works locally but not on App Engine.

For anyone who runs into this problem in the future: Some older browsers don't fully support the fetch API. You can use a polyfill like this one.

Was this page helpful?
0 / 5 - 0 ratings