reactjsreduxstorageredux-toolkitredux-persist

Error: redux-persist : Uncaught Error: Cannot find module 'redux-persist', already installed redux persist 6.0.0


I have already a redux persist installed but i don't know why i am getting this error i am just creating the simple app where I want to store the state even if user close the app so i used persist but i don't know why i am getting this error. Uncaught Error: Cannot find module 'redux-persist/lib/storage',

store.tsx

import storage from "redux-persist/lib/storage";
import userSignupReducer, {
  signupStepReducer
} from "./../pages/signup/userSignupSlice";
import { combineReducers } from "@reduxjs/toolkit";
import IAuthState from "../lib/auth/types";

import { configureStore } from "@reduxjs/toolkit";
import thunkMiddleware from "redux-thunk-recursion-detect";
import authReducer from "src/lib/auth/reducers";
import { persistReducer } from "redux-persist";
import persistStore from "redux-persist/es/persistStore";

import storageSession from "redux-persist/es/storage/session";

export interface IAppState {
auth: IAuthState;
}

const persistConfig = {
   key: "root",
   storage: storageSession
   whitelist: ["userSignupDetail", "signupStep"]
};

const rootReducer = combineReducers<IAppState>({
   userSignupDetail: userSignupReducer,
   signupStep: signupStepReducer
});
const persistedReducer = persistReducer(persistConfig, rootReducer);

export const store = configureStore({
   reducer: persistedReducer,
});

==>>. APP.tsx

import React from "react";
import ReactDOM from "react-dom";
import { Provider as ReduxProvider } from "react-redux";
import { store } from "./store";
import { PersistGate } from "redux-persist/integration/react";
import persistStore from "redux-persist/es/persistStore";

const persistor = persistStore(store);

 ReactDOM.render(
 <ReduxProvider store={store}>
    <PersistGate loading={null} persistor={persistor}>
        <App />
    </PersistGate>
</ReduxProvider>,
document.getElementById("root")
);

Solution

  • Running npm install 2 times helped to solve it.