简体   繁体   English

将Firebase与Webpack和TypeScript一起使用

[英]Using Firebase with Webpack and TypeScript

I'm trying to pull some data from a Firebase instance, but am running into an issue when trying to bind it to a variable. 我正在尝试从Firebase实例中提取一些数据,但是在尝试将其绑定到变量时遇到问题。 I'm using TypeScript and Webpack to build. 我正在使用TypeScript和Webpack进行构建。

main.ts main.ts

import * as Firebase from 'firebase';

class filter {
    constructor(){
        let ref = new Firebase('my-url-here');
    }
}

The typings and npm module are installed and working, and Visual Code brings up no errors, but when I hit the browser I get: 打字和npm模块已安装并运行,Visual Code不会出现任何错误,但是当我点击浏览器时,我得到了:

ERROR 错误

TypeError: Firebase is not a constructor

.. ..

Logging Firebase to the console returns an object with methods like auth , app and database , but none of these seem to work either (or I'm calling them incorrectly). 将Firebase登录到控制台会返回一个带有authappdatabase类的方法的对象,但这些方法似乎都不起作用(或者我打错了它们)。 Any ideas? 有任何想法吗?

A general best practice on how to incorporate Firebase into a Webpack/TypeScript would be just as welcome. 同样,将如何将Firebase集成到Webpack / TypeScript中的一般最佳实践也将受到欢迎。

In my project i had the same error: It was caused by the firebase.json file which i guess got picked up by webpack. 在我的项目我有同样的错误:它是由引起firebase.json我的猜测得到了由的WebPack拿起文件。

As i can only guess why it happened: Webpack creating a symbol "Firebase" which replaced the constructor of firebase itself. 我只能猜测为什么会发生:Webpack创建了一个符号“ Firebase”,该符号替换了Firebase本身的构造函数。

Have you done a firebase init in your directory? 您是否在目录中完成了firebase init

Also see : https://github.com/angular/angularfire2/issues/187 另请参阅: https : //github.com/angular/angularfire2/issues/187

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

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