【发布时间】:2019-09-20 21:07:21
【问题描述】:
我正在尝试将 Firebase 的 implicit initialization 和一个 React 应用程序(使用 CRA 创建)结合起来,因为这似乎是确保我不必为不同环境的配置而过分担心的好方法。
但是,在运行应用程序时,如果我尝试使用 firebase 对象,则会收到错误 Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app).
我的索引文件在应用程序文件之前包含 Firebase 文件,如果我在 Firebase 提供的 init 中放置一个断点,那么我可以看到它正在初始化 firebase 对象。
App 组件是 CRA 样板附带的组件:
mport React from 'react';
import firebase from 'firebase/app'
import 'firebase/functions'
import logo from './logo.svg';
import './App.css';
const App: React.FC = () => {
const helloWorld = firebase.functions().httpsCallable('helloWorld')
helloWorld().then(result => console.log({ result }))
return (
...
任何指针?
【问题讨论】:
-
您能否检查:1)
init.js的内容是否正确? 2) 如果您的firebase.functions().httpsCallable(在init.js的初始化之前以某种方式被调用?
标签: reactjs firebase create-react-app