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?
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'
}
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With