如何阅读Firebase Node.js模块? [英] How to read Firebase Node.js module?

查看:68
本文介绍了如何阅读Firebase Node.js模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

问题是 require 是node.js的模块"模块提供的功能.它不是ES5规范的一部分,因此它本身在Web浏览器中不可用.

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.

为了使用 require 加载模块,您将必须使用网络捆绑程序(例如Webpack 浏览器

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.

我建议阅读 Webpack入门 带您上路.

I'd recommend reading Getting started with Webpack to get you on your way.

这篇关于如何阅读Firebase Node.js模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆