Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RequireJS not loading Firebase, undefined

I'm trying to make a simple Firebase application using RequireJS and it is failing to pull in Firebase for some reason. I created a basic example that shows my problem.

Project structure is this:

/index.html
/js/main.js
/js/vendor/firebase.js
/js/vendor/require.js
/js/vendor/jquery.min.js

index.html includes:

<script src='js/vendor/require.js' data-main="js/main"></script>

main.js:

require.config({
    paths: {
        'jquery': "vendor/jquery.min",
        'firebase': "vendor/firebase"
    }
});

require(["firebase", "jquery"], function (firebase, $) {
    "use strict";

    console.log(firebase);  // undefined
    console.log($);         // function m(a, b)
});

Why does jquery load fine but firebase does not?

like image 244
mikhail Avatar asked Dec 19 '22 00:12

mikhail


1 Answers

Figured it out. Firebase does not support AMD by default, so need to add it as a shim in the require.js config:

main.js:

require.config({
    paths: {
        'jquery': "vendor/jquery.min",
        'firebase': "vendor/firebase"
    },
    shim: {
        'firebase': {
            exports: 'firebase'
        }
    }
});
like image 153
mikhail Avatar answered Dec 24 '22 02:12

mikhail