简体   繁体   English

使用AngularFirestore和firebase的“ ERROR TypeError:Object(…)不是函数”

[英]“ERROR TypeError: Object(…) is not a function” using AngularFirestore and firebase

I want to use firebase and angularfire2 in my app, first of all, I installed them, and for the declarations: 我想在我的应用程序中使用firebase和angularfire2,首先,我安装了它们,并进行了声明:

in environment.ts 在环境中

export const environment = {
    production: false,
    firebase: {
    apiKey: 'sfsdfdsff',
    authDomain: 'sfsdfdf',
    databaseURL: 'https://ng-sfsdfsf.firebaseio.com',
    projectId: 'ng-fitnesssfsdfdsf',
    storageBucket: 'ng-fsdfsdfsfdecff5.appspot.com',
   messagingSenderId: '21331323'
   }
  };

in app.module.ts, imports: 在app.module.ts中,导入:

AngularFireModule.initializeApp(environment.firebase),
AngularFirestoreModule

in the component where want to get my data: 在要获取我的数据的组件中:

import { AngularFirestore } from 'angularfire2/firestore';

until this moment I have not an error, but when I want to declare my variable in the constructor to use it: 直到这一刻,我还没有出错,但是当我想在构造函数中声明变量以使用它时:

constructor(private trainingService: TrainingService, private 
db:AngularFirestore) { }

I have an error: 我有一个错误:

ERROR TypeError: Object(...) is not a function
at eval (firestore.js:28)
at ZoneDelegate.invoke (zone.js:388)
at Zone.run (zone.js:138)

In my package.json: 在我的package.json中:

"angularfire2": "^5.0.0-rc.8.0",
"core-js": "^2.4.1",
"firebase": "^5.0.2",

and I don't know why? 我不知道为什么?

thanks for your help 谢谢你的帮助

AngularFire maintainer here, we've had a number of breaking changes as we march towards 5.0 GA. 在这里,AngularFire的维护者在迈向5.0 GA的过程中发生了许多重大变化。 In order to support Angular 6, recent releases of AngularFire require rxjs 6. While yes downgrading or pinning to an old version would work for quick and dirty fix, I wouldn't suggest that as it will leave you out of improvements to the libraries in the future. 为了支持Angular 6,最近发行的AngularFire要求使用rxjs6。虽然可以将其降级或固定到旧版本以进行快速,肮脏的修复,但我不建议这样做,因为它会使您无法对库中的库进行改进。未来。

I'd recommend upgrading rxj6 to version 6 and including rxjs-compat if you have dependencies that haven't yet upgraded: 如果您有尚未升级的依赖项,我建议将rxj6升级到版本6,并包括rxjs-compat

npm i rxjs@^6.0 rxjs-compat

Keep an eye on the angularfire changelog for important information on any breaking changes; 密切关注angularfire更改日志,以获取有关任何重大更改的重要信息; once we hit GA we will abide by semver. 一旦我们达到了GA,我们就会遵守semver。

And for reference here's the RXJS 5 => 6 migration guide . 作为参考,这里是RXJS 5 => 6迁移指南

I had same problem but i solved it. 我有同样的问题,但我解决了。 You can follow my work. 你可以关注我的工作。 This is a example for ionic. 这是离子的一个例子。

Install rxjs 安装rxjs

npm i rxjs@^6.0 rxjs-compat

import rxjs-compact to file 将rxjs-compact导入文件

import { AngularFireDatabase, AngularFireList } from 'angularfire2/database';
import { Observable } from 'rxjs-compat';
import { map } from 'rxjs-compat/operators';

https://stackoverflow.com/a/50447449/6567753 https://stackoverflow.com/a/50447449/6567753

npm install rxjs@6 rxjs-compat@6

这解决了问题

I have the same error when installing "angularfire2": 5.0.0-rc.9 . 安装"angularfire2": 5.0.0-rc.9时出现相同的错误"angularfire2": 5.0.0-rc.9

The error is gone when I rollback to 5.0.0-rc.6 . 当我回滚到5.0.0-rc.6时,错误消失了。

npm install angularfire2@5.0.0-rc.6
npm install firebase@4.12.1

Remove ^ this one in front of the version. 删除^此版本前面的。 So like this. 像这样

{
    ...

    "angularfire2": "5.0.0-rc.6",
    "firebase": "4.12.1",
}

This was my solution: 这是我的解决方案:

npm uninstall angularfire2
npm install angularfire2@5.0.0-rc.4
npm uninstall firebase
npm install firebase@4.8.0

I got the same error. 我遇到了同样的错误。 As soon as i updated rxjs with sudo npm update rxjs . 我用sudo npm update rxjs And then updated rxjs-compat with sudo npm i rxjs@latest rxjs-compat . 然后使用sudo npm i rxjs@latest rxjs-compat更新sudo npm i rxjs@latest rxjs-compat After fixing the vulnerabilities and then running ng build then ng serve . 修复漏洞后,再运行ng build然后ng serve This fixed my error. 这解决了我的错误。 (on macOS) (在macOS上)

I first uninstalled firebase and angularfire2 with: 我首先使用以下命令卸载了firebase和angularfire2:

  • npm uninstall firebase
  • npm uninstall angularfire2

And then reinstalled again with: 然后使用以下命令重新安装:

  • npm install firebase@4.12.1
  • npm install angularfire2@5.0.0-rc.6

Using ^ in the versions actually installed angularfire2@5.0.0-rc.9 so I just removed that part. 在实际安装的版本中使用^安装angularfire2@5.0.0-rc.9,因此我只删除了该部分。

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

相关问题 使用 AngularFireStore 将文档/集合返回为 object - Return document/collection as object using AngularFireStore “ERROR TypeError: Object(...) is not a function”使用 UniqueDeviceID - “ERROR TypeError: Object(…) is not a function” using UniqueDeviceID 无法在Material Datatable中使用AngularFirestore获取对象键 - Can't Fetch Object Keys Using AngularFirestore in Material Datatable TypeError:Object(…)不是函数,正在从Firebase调用数据 - TypeError: Object(…) is not a function, calling data from firebase '错误:没有AngularFirestore的提供商!' - 离子3 - 'Error: No provider for AngularFirestore!' - Ionic 3 “错误:未捕获(承诺):类型错误:对象(...)不是函数”使用 UniqueDeviceID - "Error: Uncaught (in promise): TypeError: Object(...) is not a function" using UniqueDeviceID 错误TypeError:firebase.messaging不是函数 - ERROR TypeError: firebase.messaging is not a function ionic firebase-TypeError:Object(…)在Firebase.getToken中不是函数 - ionic firebase - TypeError: Object(…) is not a function at Firebase.getToken 调用AngularFirestore时出现Javascript错误 - Javascript error when calling AngularFirestore Error Uncaught (in promise): TypeError: Object(...) is not a function - Error Uncaught (in promise): TypeError: Object(...) is not a function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM