0

I came across this error message when trying to deploy a firebase node application to a virtual private server:

/home/.../Backend/node_modules/firebase-admin/lib/firebase-namespace.js:195
        this.Promise = Promise;
                       ^
ReferenceError: Promise is not defined
    at new FirebaseNamespace (/home/.../Backend/node_modules/firebase-admin/lib/firebase-namespace.js:195:24)
    at Object.<anonymous> (/home/.../Backend/node_modules/firebase-admin/lib/default-namespace.js:5:21)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/home/.../Backend/node_modules/firebase-admin/lib/index.js:4:16)
    at Module._compile (module.js:456:26)

On my local environment, this node application runs without any problem. Both environments are having the same node, npm, and "firebase-admin" module version.

So, I followed the suggestion from here and modified the "firebase-admin" module files on the virtual server. By adding

var Promise = require('es6-promise').Promise;

to some of the module source files manually, I can get rid of the error messages. After that, nothing can be read from the firebase database.

My code section

firebaseDatabase.ref("...").once('value').then(function(snapshot){
  ....
});

which reads the contents of firebase with no problem on my local environment, never have its "then" called on the virtual server.

What am I doing wrong? Any suggestion is appreciated.

1
  • npm version: 3.10.0 ; node version: 7.1.0; v8 version: 5.4.500.36; firebase-admin version: 4.0.3; Commented Dec 4, 2016 at 22:02

2 Answers 2

3

I manage to solved the problem. Just in case if anyone run into the same issue, here are the steps how I fixed it:

  1. For my case, I removed all the modifications I made to the firebase-admin module.

  2. install "es6-promise" if you haven't. (npm install es6-promise --save)

  3. Add the following line to your "server.js" file:

require('es6-promise').polyfill();

Notice that we don't assign the result of polyfill() to any variable. The polyfill() method will patch the global environment (in this case to the Promise name) when called.

Sign up to request clarification or add additional context in comments.

Comments

0

I encountered this issue as soon as I firebase init. I did not change or added any codes in the generated scripts. I did solve the issue and was able to deploy by:

  1. Going to the functions folder "cd functions"
  2. sudo npm install es6-promise --save
  3. Browse to the functions/node_modules/firebase-admin/lib/firebase-namespace.js
  4. Add this on top

var Promise = require('es6-promise').Promise;

Your header should look like this:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var deep_copy_1 = require("./utils/deep-copy");
var error_1 = require("./utils/error");
var firebase_app_1 = require("./firebase-app");
var credential_1 = require("./auth/credential");
var DEFAULT_APP_NAME = '[DEFAULT]';
var globalAppDefaultCred;
var globalCertCreds = {};
var globalRefreshTokenCreds = {};
var Promise = require('es6-promise').Promise;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.