react-redux-firebase error 'Firebase instance does not yet exist. Check your compose function.'

喜欢而已 提交于 2021-01-27 23:32:33

问题


I'm using 'react-redux-firebase' in my project and want to integrate firebase into react-thunk. Everything works fine on local but I got error when deploy project to Firebase hosting.

Uncaught Error: Firebase instance does not yet exist. Check your compose function.

What is the problem here?

store.js

import { createStore, compose, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import { reduxFirestore, getFirestore } from 'redux-firestore';
import { reactReduxFirebase, getFirebase } from 'react-redux-firebase';

import rootReducer from './reducers/index';
import fbConfig from '../fbConfig';

/* eslint-disable no-underscore-dangle */
const composeEnhancers =
  process.env.NODE_ENV !== 'production' &&
  typeof window === 'object' &&
  window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
    ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({})
    : compose();
/* eslint-enable */

const enhancer = composeEnhancers(
  applyMiddleware(
    thunk.withExtraArgument({
      getFirebase,
      getFirestore
    })
  ),
  reduxFirestore(fbConfig),
  reactReduxFirebase(fbConfig, {
    useFirestoreForProfile: true,
    userProfile: 'users'
  })
);

const configureStore = preloadedState =>
  createStore(rootReducer, preloadedState, enhancer);

const store = configureStore({});

export default store;

fbConfig.js

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

const firebaseConfig = {
  apiKey: ...,
  authDomain: ...,
  databaseURL: ...,
  projectId: ...,
  storageBucket: ...,
  messagingSenderId: ...,
  appId: ...
};

firebase.initializeApp(firebaseConfig);
firebase.firestore().settings({});

export default firebase;

reducers/index

import { combineReducers } from 'redux';
import { firestoreReducer } from 'redux-firestore';
import { firebaseReducer } from 'react-redux-firebase';

import auth from './auth';

const rootReducers = combineReducers({
  auth,
  firestore: firestoreReducer,
  firebase: firebaseReducer
});

export default rootReducers;

回答1:


It is because you don't pass reduxFirestore(fbConfig) to compose

This might help you, Check this github link https://github.com/prescottprue/react-redux-firebase/issues/620#issuecomment-458344113



来源:https://stackoverflow.com/questions/57991307/react-redux-firebase-error-firebase-instance-does-not-yet-exist-check-your-com

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!