javascript - Firebase 和 auth 属性在 Ionic 和 Firebase 中不存在

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

我正在使用 ionic 5 和 firebase 应用程序创建基于用户的内容和按钮显示。
我正在发布并在我的应用程序中实现它。
我和使用: "firebase": "^8.1.1", "@angular/fire": "^6.1.3",现在我在 auth() 中遇到了错误和 firestore()

auth error is : Property 'auth' does not exist on type 'typeof import (TS-2339) AND firebase error is - Property 'firestore' does not exist on type '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;
                      });
                  }
                });
       
        }
       }
  

最佳答案

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

import firebase from "firebase/app";
import "firebase/auth";
import "firebase/firestore";
请注意 * as在此版本中不再是导入的一部分。

关于javascript - Firebase 和 auth 属性在 Ionic 和 Firebase 中不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65088735/

相关文章:

firebase - 如何通过云功能将 Nuxt SSR 应用部署到 Firebase?

firebase - 使用 FCM 在 Apple Safari 中推送通知

javascript - 如何使用 JavaScript 修改 CSS 类?

Angular - HostListener 指令和传递值

Angular Material Table - 映射服务器响应以满足 DataSource 契约(Contract)

android - tns-platform-declarations 的 nativescript-carousel 错误

javascript - Firebase 函数 postId 错误。 JavaScript

javascript - 在 NativeScript 应用程序中与 TextField 交互时停止键盘覆盖

javascript - 高分提醒 - 下一行和标题

javascript - 使用 jQuery 在 html 数组中设置一个值