TypeError: middleware is not a function in store

TypeError: middleware is not a function in store

我有下面的代码,用于在 react-redux 中组合 store 和 reducer。
它在我以前的应用程序中完美运行可能是由于 react 和 react-redux 版本。

TypeError: middleware is not a function

代码:

import 'rxjs'
import { createStore, combineReducers, applyMiddleware } from 'redux'
import { reducer as formReducer } from 'redux-form'
import thunk from 'redux-thunk'
import promise from 'redux-promise-middleware'
import { createEpicMiddleware, combineEpics } from 'redux-observable'
// import { createLogger } from 'redux-logger'
import user, { userEpic } from './user/duck'
import userApp, { userAppEpic } from './user-app/duck'

import app from './app'

// Bundling Epics
const rootEpic = combineEpics(
  userEpic,
  userAppEpic
)

// Creating Bundled Epic
const epicMiddleware = createEpicMiddleware()

// Define Middleware
const middleware = [
  thunk,
  promise(),
  epicMiddleware
]

// Define Reducers
const reducers = combineReducers({
  app,
  user,
  userApp,
  form: formReducer
})

// Create Store
export default createStore(reducers,
  applyMiddleware(...middleware))
epicMiddleware.run(rootEpic)

有人可以帮我解决这个问题吗?

根据 Doc:

...middleware (arguments): Functions that conform to the Redux middleware API. Each middleware receives Store's dispatch and getState functions as named arguments, and returns a function.

这意味着我们需要将函数传递给 applyMiddleware。在您的情况下,您传递的是 promise() 而不是 promise (函数),这就是它失败并出现错误的原因:

middleware is not a function

这样写:

const middleware = [ thunk, promise, epicMiddleware ];