10

I have been getting the following error since sometime in my console, i have no idea what it means and why it is originating. Please spread some light on this matter. enter image description here

it says:

persistReducer.js:50 Uncaught TypeError: action.rehydrate is not a function
at _rehydrate (persistReducer.js:50)
at persistReducer.js:54

redux-persist version on package.json: "^5.6.11" locked version: "5.9.1"

Store configuration code:

import thunk from 'redux-thunk';
import { persistStore } from 'redux-persist';
import { History, createBrowserHistory } from 'history';
import { createUserManager, loadUser } from "redux-oidc";
import { routerReducer, routerMiddleware } from 'react-router-redux';
import { createStore, applyMiddleware, compose, combineReducers, GenericStoreEnhancer, Store, StoreEnhancerStoreCreator, ReducersMapObject } from 'redux';

import * as StoreModule from './reducers';
import { ApplicationState, reducers } from './reducers';

import userManager from "./utils/userManager";

// Create browser history to use in the Redux store
const baseUrl = document.getElementsByTagName('base')[0].getAttribute('href')!;
const history = createBrowserHistory({ basename: baseUrl });

export default function configureStore(history: History, initialState?: ApplicationState) {
    // Build middleware. These are functions that can process the actions before they reach the store.
    const windowIfDefined = typeof window === 'undefined' ? null : window as any;
    // If devTools is installed, connect to it
    const devToolsExtension = windowIfDefined && windowIfDefined.__REDUX_DEVTOOLS_EXTENSION__ as () => GenericStoreEnhancer;


    const createStoreWithMiddleware = compose(
        applyMiddleware(thunk, routerMiddleware(history)),
        devToolsExtension ? devToolsExtension() : <S>(next: StoreEnhancerStoreCreator<S>) => next
    )(createStore);

    // Combine all reducers and instantiate the app-wide store instance
    const allReducers = buildRootReducer(reducers);
    const store = createStoreWithMiddleware(allReducers, initialState) as Store<ApplicationState>;
    loadUser(store, userManager);

    // Enable Webpack hot module replacement for reducers
    if (module.hot) {
        module.hot.accept('./reducers', () => {
            const nextRootReducer = require<typeof StoreModule>('./reducers');
            store.replaceReducer(buildRootReducer(nextRootReducer.reducers));
        });
    }
    const persistor = persistStore(store);
    return { store, persistor };
}

function buildRootReducer(allReducers: ReducersMapObject) {
    return combineReducers<ApplicationState>(Object.assign({}, allReducers, { routing: routerReducer }));
}

// Get the application-wide store instance, prepopulating with state from the server where available.
const initialState = (window as any).initialReduxState as ApplicationState;
export const { store, persistor } = configureStore(history, initialState);
Skaranjit
  • 764
  • 9
  • 26

3 Answers3

31

if you are working on localhost and using redux-devtools try to check Access File Url checkbox on extension options.

Access File Url

you can manage your chrome extensions by typing chrome://extensions/ in the address bar or by going to the setting and chose extensions from left menu.

Alireza
  • 2,319
  • 2
  • 23
  • 35
1

I get this error when using redux devtools, remove this and it should go away.

window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
ericbowden
  • 2,177
  • 1
  • 19
  • 21
0

Your code is using API of an older redux-persist version.

Refer to Basic Usage for the updated API:

import { persistStore, persistReducer } from 'redux-persist'

const persistConfig = {
  key: 'root',
  storage,
}

const allReducers = persistReducer(persistConfig, buildRootReducer(reducers));
Roy Wang
  • 11,112
  • 2
  • 21
  • 42