10

I have problem with loading node_modules to one of my webpage. I have npm(node.js) installed and I want to use require() function to init Firebase on my web and I don't why but it throw Reference error

ReferenceError: Can't find variable: require.

I am using bootstrap template and there are some files where the require() function works, so it's weird. Below the text is the command when I call functionrequire(). (of course Firebase is saved in node_modules using

npm firebase --save` (`../node_modules/firebase`)

also tried something like require('../firebase') but there isn't problem):

<script>
var firebase= require('firebase');
var config = {
        apiKey: "------------",
        authDomain: "------.firebaseapp.com",
        databaseURL: "https://-----.firebaseio.com/",
        storageBucket: "gs://----.appspot.com",
      };

 firebase.initializeApp(config);
</script>

Can someone help me to solve my problem? Thanks a lot!

2

1 Answer 1

8

You need to load those dependencies in your document so they are available to be required

I suggest you to use a module/dependency loader for the web like RequireJS

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.