How to read Firebase Node.js module?

2019-07-11 05:39发布

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");

error

1条回答
叛逆
2楼-- · 2019-07-11 06:24

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.

查看更多
登录 后发表回答