错误:redux-persist:未捕获错误:找不到模块“redux-persist”,已安装 redux persist 6.0.0

问题描述 投票:0回答:1

我已经安装了 redux persist,但我不知道为什么会收到此错误,我只是创建一个简单的应用程序,即使用户关闭应用程序,我也想在其中存储状态,所以我使用了 persist 但我不知道为什么我收到这个错误。未捕获的错误:找不到模块“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";

从“redux-persist/es/storage/session”导入storageSession;

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")
);
reactjs redux storage redux-toolkit redux-persist
1个回答
0
投票

运行

npm install
2次帮助解决了它。

© www.soinside.com 2019 - 2024. All rights reserved.