middleware is not a function
See original GitHub issueI can’t tell if this is a redux-thunk or a redux issue.
I have a store like this:
const store = compose(
applyMiddleware(
thunk,
logger
)
)(createStore)(counter);
This results in an error message:
./node_modules/redux/lib/utils/applyMiddleware.js:50
return middleware(middlewareAPI);
^
TypeError: middleware is not a function
at ./node_modules/redux/lib/utils/applyMiddleware.js:50:16
at Array.map (native)
at ./node_modules/redux/lib/utils/applyMiddleware.js:49:27
at Object.<anonymous> (./index.js:63:105)
at Module._compile (module.js:425:26)
at Object.Module._extensions..js (module.js:432:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Function.Module.runMain (module.js:457:10)
at startup (node.js:136:18)
If I comment out thunk above, it continues:
const store = compose(
applyMiddleware(
// thunk,
logger
)
)(createStore)(counter);
store.dispatch({ type: INCREMENT });
store.dispatch({ type: INCREMENT });
store.dispatch({ type: DECREMENT });
$ node --harmony_default_parameters --harmony_destructuring index.js
will dispatch { type: 'INCREMENT' }
state after dispatch 1
will dispatch { type: 'INCREMENT' }
state after dispatch 2
will dispatch { type: 'DECREMENT' }
state after dispatch 1
Issue Analytics
- State:
- Created 8 years ago
- Comments:34
Top Results From Across the Web
TypeError: middleware is not a function - Stack Overflow
I was getting the same error TypeError: middleware is not a function. import { createStore, combineReducers, applyMiddleware } from "redux"; ...
Read more >TypeError: middleware is not a function #144 - GitHub
Hello, I'm trying to create a middleware. Giving this error: TypeError: middleware is not a function Here is my code block: import ...
Read more >[Solved]-TypeError: middleware is not a function-Reactjs
I was getting the same error TypeError: middleware is not a function. import { createStore, combineReducers, applyMiddleware } from "redux"; import { ...
Read more >Middleware | NestJS - A progressive Node.js framework
Middleware is a function which is called before the route handler. Middleware functions have access to the request and response objects, and the...
Read more >Using middleware - Express.js
If the current middleware function does not end the request-response cycle, it must call next() to pass control to the next middleware function....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
use “import thunk from “redux-thunk”;” not “import {thunk} from “redux-thunk”;”
After facing recently same issue and none of the above worked for me I’ve tried with importing just {createLogger} that sorted the issue when new logger instance was passed to applyMiddleware.
Works under Typescript and Babel because in my attempts to isolate the route cause I’ve switched to each of them. The issue is observed with latest redux packages at the time of my writing and solution is tested only against them