Getting an error: “Has no exported member AngularFire, AuthProviders, AUthMethods, FirebaseListObservable” in AngularFire2?

﹥>﹥吖頭↗ 提交于 2019-12-17 15:51:59

问题


I am new to Angular 4, so I am creating a firebase chat app with Angular 4, and then when I import some modules like this:

import { AngularFire, AuthProviders, AuthMethods,FirebaseListObservable } from 'angularfire2';

I get an error for each module that says

Has no exported member AngularFire, AuthProviders, AUthMethods, FirebaseListObservable.

Thank you


回答1:


UP TO DATE(Ver 5.0.0-rc3):

While getting this error, this means you are using old Database API. This can solved by importing FirebaseListObservable from depracated module(See also @Ashish Jha answer):

import { AngularFireModule } from 'angularfire2';
import { AngularFireDatabase, FirebaseListObservable, FirebaseObjectObservable } from 'angularfire2/database-deprecated';

It's recommended to use the latest API since AngularFire 5.0 brings new API for the Realtime Database. Refer upgrade guide.


ORIGINAL ANSWER: AngularFire2 has separate its modules since 4.0.0+.

you can import those two module if you want use auth of angularfire2, see their change log :

import {AngularFireModule} from 'angularfire2';
// for auth    
import {AngularFireAuthModule} from 'angularfire2/auth';
// for database
import {AngularFireDatabaseModule} from 'angularfire2/database';

and import Auth and Observable(AuthMethods can be found in AngularFireAuth) type by:

// for auth
import { AngularFireAuth } from 'angularfire2/auth';
// for database
import { AngularFireDatabase } from 'angular2/database';
// for Observables
import {FirebaseListObservable, FirebaseObjectObservable } from 'angularfire2/database';



回答2:


The solution that worked for me was to change this line

import { AngularFire, AuthProviders, AuthMethods,FirebaseListObservable } from 'angularfire2'; 

to

import { AngularFireAuth } from 'angularfire2/auth';

import { AngularFireDatabase, FirebaseListObservable } from "angularfire2/database-deprecated";

You can read more about it here https://github.com/angular/angularfire2/blob/master/CHANGELOG.md




回答3:


use AngularFireObject instead of FirebaseObjectObservable and AngularFireList instead of FirebaseListObservable ,this has been updated since AngularFire5

if you want more details checkout https://github.com/angular/angularfire2/blob/master/docs/version-5-upgrade.md



来源:https://stackoverflow.com/questions/43990887/getting-an-error-has-no-exported-member-angularfire-authproviders-authmethod

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!