期望根减速器是一个函数

Expected the root reducer to be a function

我遇到了这个错误:

Uncaught Error: Expected the root reducer to be a function. Instead, received:''

我已经尝试了所有我能找到的答案,但是 none 成功了,我希望你们能帮助我

我的rootReducer

import {combineReducers} from 'redux'
import changeCategoryReducer from './changeCategoryReducer'
import categoryListReducer from './categoryListReducer'
import productListReducer from './productListReducer'
import cartReducer from './cartReducer'
import saveProductReducer from './saveProductReducer'


const rootReducer = combineReducers({
   changeCategoryReducer,
    categoryListReducer,
    productListReducer,
    cartReducer,
    saveProductReducer
});

export default rootReducer;

配置商店

import {createStore, applyMiddleware} from 'redux'
import * as rootReducer from './index.js'
import thunk from 'redux-thunk'

export default function configureStore(){
    return createStore(rootReducer, applyMiddleware(thunk))
}

index.js

import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './components/root/App';
import reportWebVitals from './reportWebVitals';
import 'bootstrap/dist/css/bootstrap.min.css';
import { Provider } from 'react-redux'
import configureStore from './redux/reducers/configureStore'
import 'alertifyjs/build/css/alertify.min.css'
import { BrowserRouter } from 'react-router-dom'


const store = configureStore();

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
  <React.StrictMode>
    <BrowserRouter>
      <Provider store={store}>
        <App />
      </Provider>
    </BrowserRouter>
  </React.StrictMode>
);
reportWebVitals();

您没有在商店创建中正确导入 rootReducer。 而不是导入 *,您应该导入 default 导出:

import {createStore, applyMiddleware} from 'redux'
import rootReducer from './index.js' // <-- change here
import thunk from 'redux-thunk'

export default function configureStore(){
    return createStore(rootReducer, applyMiddleware(thunk))
}

使用 import * as rootReducer from './index.js' 意味着你最终得到一个像这样的对象:

rootReducer: {
  default: createReducer(...)
}