简体   繁体   English

如何阅读Firebase Node.js模块?

[英]How to read Firebase Node.js module?

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. 我正在运行聚合物入门套件应用程序,并且需要Firebase连接,但是我不知道为什么浏览器说的require是未定义的。

$ npm install firebase --save

var Firebase = require("firebase");

错误

The problem is that require is a function provided by node.js's 'module' module. 问题是require是node.js的“模块”模块提供的功能。 It is not part of the ES5 spec, and so it is not natively available in web browsers. 它不是ES5规范的一部分,因此它本身在Web浏览器中不可用。

In order to load modules using require , you will have to use a web bundler (like Webpack , Browserify or RequireJS ). 为了使用require加载模块,您将必须使用Web捆绑程序(例如WebpackBrowserifyRequireJS )。 This will bundle together all of the JS in your project into a single file, automatically handling calls to require . 这会将项目中的所有JS捆绑到一个文件中,自动处理对require调用。

I'd recommend reading Getting started with Webpack to get you on your way. 我建议阅读“ Webpack入门”以助一臂之力

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM