Skip to content Skip to sidebar Skip to footer

Firebase Web 2.4.0 Promises In Nodejs

I am having some issues with error callbacks from Firebase Web in a Node application. The original issue was that the error callback from a .set was apparently not being fired whe

Solution 1:

I think there are 3 things going on:

  1. node v0.10.28 doesn't come with a builtin implementation of Promise.
  2. The firebase module bundles a Promise/A+-compatible implementation that it uses when there isn't already one defined.
  3. The implementation we ship with firebase is a pure Promise/A+ implementation and doesn't include .catch().

However .catch() is very useful and although not part of Promise/A+ it is semi-standard so we're planning to go ahead and add it to our bundled Promise implementation in an upcoming release, which should resolve your issue.

In the meantime, you could do any of the following:

  • Use .then(null, function(err) { ... }) instead of .catch(function(err) { ... })
  • Import a suitable Promise implementation into your environment. E.g. global.Promise = require('rsvp').Promise;
  • Upgrade to node v0.12.x or newer, which comes with a builtin Promise implementation (that supports .catch()).

Solution 2:

Firebase uses the underlying Promise implementation when that's available. It looks like the Promises implementation in your node environment doesn't support catch(), which is not required.

Since this:

.then(handleSuccess).catch(handleError)

is just a different notation for:

.then(handleSuccess, handleError)

You can go with the latter to get it working.

Solution 3:

A copy of my initial comment:

Perhaps your version of node doesn't implement the promise .catch function, but the browser does. It's tough to say without knowing more about your node setup.

One thing to try is to pull in a separate library for handling promises. Bluebird is a popular one. Try doing npm install bluebird, and then at the top of your file that uses promises Promise = require("bluebird").

Some more information:

I see now you are using the es6-promises polyfill. Again, I don't know enough about your node/transpiling setup to be definitive. A guess would be that it is possible that the Firebase sdk source would need to be transpiled with the polyfill for it to take effect for the sdk. So it may still be worth temporarily pulling in bluebird as a sanity check.

Post a Comment for "Firebase Web 2.4.0 Promises In Nodejs"