reduxjs/redux · error · Error

Expected the root reducer to be a function. Instead, receive

Error message

Expected the root reducer to be a function. Instead, received: '${kindOf(reducer)}'

What it means

createStore's first argument must be the root reducer function. If it is anything else (undefined, object, string, etc.), Redux cannot build the store because dispatch() would call reducer(state, action). The check is the very first guard in createStore so it fails before any setup work.

Source

Thrown at src/createStore.ts:98

  PreloadedState = S
>(
  reducer: Reducer<S, A, PreloadedState>,
  preloadedState?: PreloadedState | undefined,
  enhancer?: StoreEnhancer<Ext, StateExt>
): Store<S, A, UnknownIfNonSpecific<StateExt>> & NoInfer<Ext>
export function createStore<
  S,
  A extends Action,
  Ext extends {} = {},
  StateExt extends {} = {},
  PreloadedState = S
>(
  reducer: Reducer<S, A, PreloadedState>,
  preloadedState?: PreloadedState | StoreEnhancer<Ext, StateExt> | undefined,
  enhancer?: StoreEnhancer<Ext, StateExt>
): Store<S, A, UnknownIfNonSpecific<StateExt>> & NoInfer<Ext> {
  if (typeof reducer !== 'function') {
    throw new Error(
      `Expected the root reducer to be a function. Instead, received: '${kindOf(
        reducer
      )}'`
    )
  }

  if (
    (typeof preloadedState === 'function' && typeof enhancer === 'function') ||
    (typeof enhancer === 'function' && typeof arguments[3] === 'function')
  ) {
    throw new Error(
      'It looks like you are passing several store enhancers to ' +
        'createStore(). This is not supported. Instead, compose them ' +
        'together to a single function. See https://redux.js.org/tutorials/fundamentals/part-4-store#creating-a-store-with-enhancers for an example.'
    )
  }

  if (typeof preloadedState === 'function' && typeof enhancer === 'undefined') {

View on GitHub (pinned to 3084fc33bb)

Solutions

  1. Verify the reducer import: log `typeof rootReducer` right before createStore and ensure it is 'function'.
  2. If combining slices, wrap them: `createStore(combineReducers({ todos, filter }))`.
  3. Fix import statements: use `import rootReducer from './reducers'` for a default export, or `import { rootReducer } from './reducers'` / `import * as ...` for named exports.
  4. Resolve circular dependencies (move the store creation to a leaf module, or lazy-import the reducer).

Example fix

// before
import rootReducer from './reducers'   // module has no default export
const store = createStore(rootReducer)  // rootReducer is undefined

// after
import { rootReducer } from './reducers'
const store = createStore(rootReducer)
Defensive patterns

Strategy: type-guard

Validate before calling

if (typeof rootReducer !== 'function') {
  throw new TypeError(`rootReducer must be a function, got ${typeof rootReducer}`)
}
const store = createStore(rootReducer)

Type guard

const isReducer = (x): x is (s:any, a:any)=>any => typeof x === 'function'

Prevention

When it happens

Trigger: createStore(undefined) — reducer import resolved to undefined; createStore(combineReducers({...})) where combineReducers was imported from a wrong path; createStore({todos, filter}) passing a map directly instead of combineReducers(map); createStore called with no arguments at all.

Common situations: Circular import that makes the reducer undefined at module eval time; default-vs-namespace import mismatch on the reducer module; refactoring that moved the reducer file without updating the import; passing a slice map directly to createStore (forgetting combineReducers).

Related errors


AI-assisted analysis of reduxjs/redux@3084fc33bb (2026-08-12). Data as JSON: /api/errors/d4f09dd349bd6585. Report an issue: GitHub.