【问题标题】:firebase and auth property does not exist in Ionic and FirebaseFirebase 和 auth 属性在 Ionic 和 Firebase 中不存在
【发布时间】:2020-12-01 10:26:53
【问题描述】:

我正在使用 ionic 5firebase 应用程序创建基于用户的内容和按钮显示。 我正在发布并在我的应用程序中实现它。

我和使用: "firebase": "^8.1.1","@angular/fire": "^6.1.3",

现在auth()firestore() 出现错误

auth 错误是:“typeof 导入”类型上不存在属性“auth” (TS-2339) 并且 firebase 错误是 - 属性“firestore”不存在 关于类型'typeof import

    import { Component, OnInit } from "@angular/core";
    import * as firebase from "firebase/app";
    import "firebase/auth";
    import "firebase/firestore";
     
    @Component({
      selector: "app-places",
      templateUrl: "./posts.page.html",
      styleUrls: ["./posts.page.scss"],
    })
    export class PlacesPage implements OnInit {
      constructor() {}
      //firestore = firebase.firestore();
      public isAdmin = false; 
      ngOnInit() {


    //Property 'auth' does not exist on type 'typeof import
            firebase.auth().onAuthStateChanged((user) => {
              if (user) {
                firebase


                  .firestore()    //Property 'firestore' does not exist on type 'typeof import
                 

 

    .doc(`s/${user.id}`)
                      .get()
                      .then((userProfileSnapshot) => {
                        this.isAdmin = userProfileSnapshot.data().isAdmin;
                      });
                  }
                });
       
        }
       }
  

【问题讨论】:

  • 请编辑问题以显示您正在使用的 firebase 模块的版本。它将在您的 package.json 中。
  • @DougStevenson 我更新了问题。谢谢

标签: javascript angular firebase ionic-framework google-cloud-firestore


【解决方案1】:

请查看importing Firebase SDKs using a module bundler 的文档。从 Firebase SDK 版本 8.0.0 开始,您现在必须像这样导入:

import firebase from "firebase/app";
import "firebase/auth";
import "firebase/firestore";

请注意,* as 在此版本中不再是导入的一部分。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-08
    • 2017-03-10
    • 1970-01-01
    • 2019-03-24
    • 1970-01-01
    • 2018-01-15
    • 1970-01-01
    • 2016-11-21
    相关资源
    最近更新 更多