首页 > 解决方案 > 离子 - Firebase 身份验证错误

问题描述

这是我的 register-form.component.ts 文件。

import { Component } from '@angular/core';
import { AngularFireAuth } from 'angularfire2/auth';
import { ToastController } from 'ionic-angular';
import { Account } from '../../models/accounts/account.interface';

@Component({
  selector: 'app-register-form',
  templateUrl: 'register-form.component.html'
})
export class RegisterFormComponent {

  account = {} as Account; 

  constructor(private afAuth: AngularFireAuth, private toast: ToastController) {

  }

  async register() {

    try{
      const result = await this.afAuth.auth.createUserWithEmailAndPassword(this.account.email, this.account.password);
      this.toast.create({
        message: "Account succesfully created!!",
        duration: 3000
      }).present();
      console.log(result);
    } catch(e){
      console.error(e);
      this.toast.create({
        message: e.message,
        duration: 3000
      }).present();
    }

  }  

}

当我尝试通过构造函数传递 AngularFireAuth 变量时,它会显示此运行时错误。

错误:未捕获(承诺):TypeError: WEBPACK_IMPORTED_MODULE_1_firebase_app .app 不是函数 TypeError:WEBPACK_IMPORTED_MODULE_1_firebase_app .app 不是函数

我是离子新手。请帮我解决这个错误。

标签: typescriptfirebaseionic-frameworkfirebase-authenticationangularfire2

解决方案


先尝试 webpack 模块。做那个运行

npm 删除 webpack -g

然后再次安装 webpack

npm i webpack --save-dev


推荐阅读