I am running a polymer starter kit app and I need a firebase connection, but I don't know why the browser say that require is undefined.
$ npm install firebase --save
var Firebase = require("firebase");
I am running a polymer starter kit app and I need a firebase connection, but I don't know why the browser say that require is undefined.
$ npm install firebase --save
var Firebase = require("firebase");
The problem is that require
is a function provided by node.js's 'module' module. It is not part of the ES5 spec, and so it is not natively available in web browsers.
In order to load modules using require
, you will have to use a web bundler (like Webpack, Browserify or RequireJS). This will bundle together all of the JS in your project into a single file, automatically handling calls to require
.
I'd recommend reading Getting started with Webpack to get you on your way.