{"record":{"id":"d4f09dd349bd6585","repo":"reduxjs/redux","slug":"expected-the-root-reducer-to-be-a-function-instea","errorCode":null,"errorMessage":"Expected the root reducer to be a function. Instead, received: '${kindOf(reducer)}'","messagePattern":"Expected the root reducer to be a function\\. Instead, received: '(.+?)'","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/createStore.ts","lineNumber":98,"sourceCode":"  PreloadedState = S\n>(\n  reducer: Reducer<S, A, PreloadedState>,\n  preloadedState?: PreloadedState | undefined,\n  enhancer?: StoreEnhancer<Ext, StateExt>\n): Store<S, A, UnknownIfNonSpecific<StateExt>> & NoInfer<Ext>\nexport function createStore<\n  S,\n  A extends Action,\n  Ext extends {} = {},\n  StateExt extends {} = {},\n  PreloadedState = S\n>(\n  reducer: Reducer<S, A, PreloadedState>,\n  preloadedState?: PreloadedState | StoreEnhancer<Ext, StateExt> | undefined,\n  enhancer?: StoreEnhancer<Ext, StateExt>\n): Store<S, A, UnknownIfNonSpecific<StateExt>> & NoInfer<Ext> {\n  if (typeof reducer !== 'function') {\n    throw new Error(\n      `Expected the root reducer to be a function. Instead, received: '${kindOf(\n        reducer\n      )}'`\n    )\n  }\n\n  if (\n    (typeof preloadedState === 'function' && typeof enhancer === 'function') ||\n    (typeof enhancer === 'function' && typeof arguments[3] === 'function')\n  ) {\n    throw new Error(\n      'It looks like you are passing several store enhancers to ' +\n        'createStore(). This is not supported. Instead, compose them ' +\n        'together to a single function. See https://redux.js.org/tutorials/fundamentals/part-4-store#creating-a-store-with-enhancers for an example.'\n    )\n  }\n\n  if (typeof preloadedState === 'function' && typeof enhancer === 'undefined') {","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/reduxjs/redux/blob/3084fc33bb23ab4cab4796172eafe342da4e73d9/src/createStore.ts#L80-L116","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","solutions":["Verify the reducer import: log `typeof rootReducer` right before createStore and ensure it is 'function'.","If combining slices, wrap them: `createStore(combineReducers({ todos, filter }))`.","Fix import statements: use `import rootReducer from './reducers'` for a default export, or `import { rootReducer } from './reducers'` / `import * as ...` for named exports.","Resolve circular dependencies (move the store creation to a leaf module, or lazy-import the reducer)."],"exampleFix":"// before\nimport rootReducer from './reducers'   // module has no default export\nconst store = createStore(rootReducer)  // rootReducer is undefined\n\n// after\nimport { rootReducer } from './reducers'\nconst store = createStore(rootReducer)","handlingStrategy":"type-guard","validationCode":"if (typeof rootReducer !== 'function') {\n  throw new TypeError(`rootReducer must be a function, got ${typeof rootReducer}`)\n}\nconst store = createStore(rootReducer)","typeGuard":"const isReducer = (x): x is (s:any, a:any)=>any => typeof x === 'function'","tryCatchPattern":null,"preventionTips":["Verify the reducer import path and export style.","Use TypeScript so createStore's signature rejects non-function reducers at compile time.","Log `typeof rootReducer` during store setup in dev.","Avoid circular imports that postpone reducer definition."],"tags":["redux","createstore","reducer","import","argument-validation"],"backgroundTag":null,"analyzedSha":"3084fc33bb23ab4cab4796172eafe342da4e73d9","analyzedAt":"2026-08-12T13:21:41.727Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}