我在我的项目中使用“react-redux-firebase”,并希望将 firebase 集成到 react-thunk 中。在本地一切正常,但在将项目部署到 Firebase 托管时出现错误。
未捕获的错误:Firebase 实例尚不存在。检查您的撰写功能。
这里有什么问题?
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;
减速器/索引
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;