我正在开发一个react应用程序,最近在我的mac上升级到node12.10.0,遇到了很多包问题。我在我的项目中升级了很多包,但当我调用persistor.purge((:时,似乎出现了一个错误
TypeError: Cannot read property 'getItem' of undefined
getStoredState
node_modules/redux-persist/es/getStoredState.js:19
16 | deserialize = defaultDeserialize;
17 | }
18 |
> 19 | return storage.getItem(storageKey).then(function (serialized) {
20 | if (!serialized) return undefined;else {
21 | try {
22 | var state = {};
View compiled
Object../src/index.js
src/index.js:26
23 | debugger;
24 | debugger;
25 |
> 26 | getStoredState({}).then((err, restoredState) => {
27 | if(restoredState) {
28 | let storedAppVersion = restoredState.app ? restoredState.app.version : null;
29 | // Purge the persisted state if the version has changed
当我在以下reducer代码中点击persistor.purge((时,错误本身似乎发生了:
case REHYDRATE:
let isValid = isTokenInLocalStorageValid();
if(isValid) {
let storedState = action.payload.user;
let newState = Object.assign({}, storedState, { status: null });
return newState;
}
debugger;
debugger;
persistor.purge();
这是我创建潜望镜和商店的代码:
export const history = createBrowserHistory();
const sagaMiddleware = createSagaMiddleware();
const initialState = {}
const middleware = [
thunk,
sagaMiddleware,
routerMiddleware(history)
]
const composedEnhancers = compose(
applyMiddleware(...middleware)
)
debugger;
debugger;
const persistConfig = {
key: 'root',
storage: localforage,
}
const persistedReducer = persistReducer(persistConfig, rootReducer(history));
const store = createStore(
persistedReducer,
initialState,
composedEnhancers
)
store.runSaga = sagaMiddleware.run(sagas);
let persistor = persistStore(store)
export default () => {
return { store, persistor }
}
我查看了设置示例,没有看到问题可能在哪里。
出于某种原因,它说存储是未定义的。我相信你很可能已经检查过了,但在错误指向的文件中;您正在导入存储吗?