Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReferenceError: Can't find variable: require

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!

like image 231
preneond Avatar asked Oct 17 '16 13:10

preneond


1 Answers

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

like image 150
Pablo Recalde Avatar answered Oct 06 '22 02:10

Pablo Recalde