Search code examples
javascriptfirebaserequirejsaurelia

firebase js version > 3.6.3 breaks bundling with the aurelia-cli


I use the aurelia-cli to bundle my assets. requiring modules is handled by requirejs.

To use firebase, I specifically bundle the file firebase-browser.js:

// aurelia.json
    [...]
    {
        "name": "firebase",
        "path": "../node_modules/firebase/",
        "main": "firebase-browser"
    }

Up to version 3.6.2 of the firebase npm package everything works as expected. But from version 3.6.3 on the following error occurs in the browser:

ReferenceError: global is not defined

The part of the bundle that causes the problem:

define('firebase/app',['require','exports','module'],function (require, exports, module) {var firebase = (function(){
// minified stuff
firebase.SDK_VERSION = "3.6.3";
return firebase;}).call(global); // <--- ERROR
module.exports = firebase;

The release notes for firebase say

3.6.3: Changed the packaging of browser npm modules to fix an issue that occurred when using Firebase Storage with the Browserify and webpack module bundlers.

Any ideas how to fix this?


Solution

  • For compatibility with Node, Browserify defines global to be window.

    You should be able to solve your problem by defining it someplace before Firebase is loaded:

    window.global = window;
    

    It's not pretty, but it should fix things.