Redux store throws 'does not have a valid reducer'
Store does not have a valid reducer. Make sure the argument passed to combineReducers is an object whose values are reducers.Short answer
configureStore needs either one reducer function or an object whose values are reducer functions. The error appears when it gets something else: a whole slice instead of slice.reducer, an undefined import, an empty object, or a reducer that returns undefined. Log what you pass in, then fix the import or the return.
Fix it fast
1Find out which cause you have
Print the reducer map right before configureStore. Every value must be a function, never undefined or an object.
const reducer = { posts: postsReducer, users: usersReducer }; console.log(Object.entries(reducer).map(([k, v]) => [k, typeof v]));2Match what you see, then jump to its fix
- 1
typeof prints 'undefined' or 'object' for one keyAn import is undefined, or you passed the slice instead of slice.reducerFix - 2
The call is configureStore({}) or reducer is not set, or the map is nested one level too deepThe reducer option is empty or has the wrong shapeFix - 3
A slice reducer written by hand has an early return, or no default caseA reducer returns undefinedFix
- 1
What does the error look like?
Store does not have a valid reducer. Make sure the argument passed to combineReducers is an object whose values are reducers.
Cause 1 of 3
An import is undefined, or you passed the slice instead of slice.reducer
1Check
A slice file default-exports todosSlice.reducer. Importing with braces, or passing the slice object, gives undefined or an object.
grep -rn "export default" src/features/2Fix
Export the reducer as the default and import it without braces, as in the Redux migration guide.
// postsSlice.js
export default postsSlice.reducer
// store.js
import postsReducer from '../features/posts/postsSlice'3Verify
The log now shows 'function' for every key.
npm testConfirmed by redux.js.org
Cause 2 of 3
The reducer option is empty or has the wrong shape
1Check
reducer accepts a single reducer function, or an object of slice reducers that configureStore passes to combineReducers.
grep -rn "configureStore" src/2Fix
Give it a function, or a flat object of slice reducers.
const store = configureStore({
reducer: { todos: todosReducer, visibility: visibilityReducer },
})3Verify
Create the store and read its state.
console.log(store.getState())Confirmed by redux.js.org
Cause 3 of 3
A reducer returns undefined
1Check
combineReducers throws when a reducer returns undefined, and it probes each reducer by passing undefined as state, even if preloadedState is set.
grep -rn "switch (action.type)" src/2Fix
Give the state parameter a default and return state for unknown actions.
export default function counter(state = 0, action) {
switch (action.type) {
case 'INCREMENT':
return state + 1
default:
return state
}
}3Verify
Run the store once; the error goes away.
console.log(counter(undefined, { type: '@@init' }))Confirmed by redux.js.org
How do I stop it coming back?
- Use createSlice and export slice.reducer as the default, so hand-written switch statements are rare.
- Add one test that creates the store and checks getState() has every expected key.
- Keep the reducer map flat: one key per slice.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Web apps
createStore is struck through and marked @deprecated in Redux
createStore shown with a strikethrough and marked @deprecated in the editor
createStore is marked @deprecated since Redux 4.2.0, which only draws a strikethrough in your editor.
2 causes, each with a fixWeb apps
Module not found for antd/dist/antd.less after upgrading to Ant Design 5
Module not found: Error: Can't resolve 'antd/dist/antd.less'
Ant Design 5 dropped Less and the bundled CSS file for CSS-in-JS, so antd/dist/antd.less no longer exists.
3 causes, each with a fixWeb apps
Astro Code component fails inside a React component
Astro components cannot be rendered directly via function call
Astro components such as Code only exist on the server and render static HTML.
2 causes, each with a fixWeb apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
How to catch and handle a 422 from Axios in a Redux thunk
action.error.message is 'Rejected' and action.payload is undefined
A 422 means the server read the request but cannot process its content, so repeating it unchanged fails again.
4 causes, each with a fixWeb apps
axios gets 429 Too Many Requests from a React app
429 (Too Many Requests)
A 429 comes from the server or an API gateway, not from axios: your client sent too many requests in a window.
4 causes, each with a fix