【问题标题】:Error: FIREBASE FATAL ERROR: Cannot parse Firebase url. Please use https://<YOUR FIREBASE>.firebaseio.com but database url is not firebaseio.com expo错误:FIREBASE 致命错误:无法解析 Firebase 网址。请使用 https://<YOUR FIREBASE>.firebaseio.com 但数据库 url 不是 firebaseio.com expo
【发布时间】:2021-04-19 20:29:22
【问题描述】:

当我尝试在 firebase 数据库中写入数据时,我正在为我的 ios 应用程序使用 Expo SDK,但出现错误。 错误:FIREBASE 致命错误:无法解析 Firebase URL。请使用 https://.firebaseio.com*

我的 firebase 配置文件是

const firebaseConfig = {
  apiKey: "xxxxxx",
  authDomain: "xxxxxx.firebaseapp.com",
  databaseURL: "https://xxxxxxxxxxxxxx.europe-west1.firebasedatabase.app",
  projectId: "xxxxx",
  storageBucket: "xxxxxxx.appspot.com",
  messagingSenderId: "xxxxxxxxx",
  appId: "xxxxxxxxxx",
  measurementId: "xxxxxx"
};

我存储数据的函数是


signUp = () => {
   const user = firebase.auth().currentUser;
   let userid = user.uid;

   firebase
     .database()
     .ref(`users/${userid}`)
     .set({
       firstname: this.state.firstname,
       lastname: this.state.lastname,
       password: this.state.password,
       email: this.state.email,
       dob: this.state.dob,
       postcode: this.state.postcode,
     })
     .then(() => {
       alert("user created");
     })
     .catch((err) => {
       alert("error");
     });
 };

我的数据库规则设置为 true 以进行读写。

我已经尝试了以下数据库 URL,但它们都不起作用。

const firebaseConfig = {

  databaseURL: "https://xxxxxxxxxxxxxx.europe-west1.firebaseio.com",
 
};
const firebaseConfig = {

  databaseURL: "https://xxxxxxxxxxxxxx.firebaseio.com",
 
};

请帮忙

【问题讨论】:

  • 查看错误消息的确切来源真的很有帮助。但我建议将 URL 显式传递到数据库初始化中:firebase.database().ref("https://&lt;DATABASE_NAME&gt;.firebasedatabase.app") 作为一种解决方法。
  • @FrankvanPuffelen 我试过了,它给了我同样的错误

标签: firebase react-native firebase-realtime-database expo react-native-ios


【解决方案1】:

Firebase 软件包 升级到最新版本可解决此问题

"firebase": "^8.2.3"

【讨论】:

    【解决方案2】:

    firebaser 在这里

    Expo 似乎以某种方式将您锁定在 2020 年 2 月发布的 Firebase SDK version 7.9 上。这早于添加了 firebasedatabase.app 网址,这发生在 2020 年 5 月,并在版本 7.15.4 中发布JavaScript SDK,据我所知。

    当我将 SDK 依赖项升级到 7.14.5 时,问题消失了,尽管 Expo Snack 编辑器在我这样做时显示错误:

    {
      "dependencies": {
        "react-native-paper": "3.6.0",
        "expo-constants": "~9.3.1",
        "firebase": "7.14.5"
      }
    }
    

    我的建议是升级到最新版本的 SDK,如 Firebase 控制台和文档中的配置 sn-ps 所示。

    【讨论】:

    • 我升级了我的依赖,它仍然给出了同样的错误。我的依赖是{ "@expo/vector-icons": "^12.0.0", "expo": "~40.0.0", "expo-constants": "^9.3.5", "expo-firebase-recaptcha": "^1.3.0", "expo-font": "~8.4.0", "expo-linking": "~2.0.0", "expo-splash-screen": "~0.8.0", "expo-status-bar": "~1.0.3", "expo-web-browser": "~8.6.0", "firebase": "^7.14.5", "react": "16.13.1", "react-dom": "16.13.1", "react-native": "https://github.com/expo/react-native/archive/sdk-40.0.1.tar.gz" }
    • 这很有趣,因为它在这里对我有用:snack.expo.io/ij7acLi0V
    • 是的,很奇怪。我正在使用最新的 SDK 依赖项,但我不确定出了什么问题。我会继续调试的
    • 嘿@gangataarun。你在这里有什么进展吗?鉴于我能够使用 Firebase SDK 版本重现该消息,并且能够通过升级到较新版本来修复它,我非常确信它一定与版本相关。如果还没修好,能不能把它复制成世博小吃,让我看看?
    【解决方案3】:

    你初始化配置了吗?像这样。

    import firebase from 'firebase/app';
    import 'firebase/firestore';
    import 'firebase/database';
    import 'firebase/auth';
    import 'firebase/storage';
    import 'firebase/functions';
    
    interface ConfigProps {
        apiKey: string;
        authDomain: string;
        databaseURL: string;
        projectId: string;
        storageBucket: string;
        messagingSenderId: string;
        appId: string;
    }
    
    const config: ConfigProps = {
        apiKey: '******************',
        authDomain: '******************',
        databaseURL: '******************',
        projectId: '******************,
        storageBucket: '******************',
        messagingSenderId: '******************',
        appId: '******************',
    };
    
    firebase.initializeApp(config);
    firebase.firestore();
    
    export default firebase;
    

    【讨论】:

    • 是的,我已经初始化了我在 app.js 中调用的配置 import * as firebase from "firebase"; import firebaseAppconfig from "./variables/firebase"; // PROVIDE VALID FIREBASE CONFIG HERE // https://firebase.google.com/docs/web/setup const FIREBASE_CONFIG: any = firebaseAppconfig; try { if (FIREBASE_CONFIG.apiKey) { firebase.initializeApp(FIREBASE_CONFIG); } } catch (err) { // ignore app already initialized error on snack }
    猜你喜欢
    • 2021-11-07
    • 2019-05-24
    • 1970-01-01
    • 1970-01-01
    • 2014-11-10
    • 2019-10-10
    • 2016-03-08
    • 2018-03-15
    • 1970-01-01
    相关资源
    最近更新 更多