redux-persist icon indicating copy to clipboard operation
redux-persist copied to clipboard

redux-persist failed to create sync storage. falling back to noop storage

Open kaleshasheik opened this issue 5 years ago • 47 comments

I have configured redux-perist in my React.js application like below. While launching application, I am getting below error in console. How to fix it ?

Error: redux-persist failed to create sync storage. falling back to noop storage

import storage from 'redux-persist/lib/storage' const persistConfig = { key: 'root', storage, }

kaleshasheik avatar Jun 05 '20 06:06 kaleshasheik

I have the exact same issue, strangely enough resaving the project does make it suddenly work. Using AsyncStorage from the react native community also doesnt fix it.

mohammedmulazada avatar Jun 06 '20 10:06 mohammedmulazada

Changing redux-persist to version ^5.10.0 does somehow fix this issue.

mohammedmulazada avatar Jun 06 '20 10:06 mohammedmulazada

Same issue even when using Expo 38 and importing from @react-native-community/async-storage. With Expo 38, async storage is now imported from react-native-community instead of react-native, but this doesn't seem to resolve this issue.

wardjk87 avatar Jul 06 '20 22:07 wardjk87

Changing redux-persist to version ^5.10.0 does somehow fix this issue. This is the only thing that has worked for me. This seems like a winner for now.

joshwinter avatar Jul 12 '20 00:07 joshwinter

I'm having the same issue with 6.0.0 during SSR in dev mode. Is it possible to disable this warning when typeof window === "undefined"?

rokinsky avatar Jul 13 '20 23:07 rokinsky

I'm having the same issue with 6.0.0 during SSR in dev mode. Is it possible to disable this warning when typeof window === "undefined"?

btw, here is my workaround:

import createWebStorage from "redux-persist/lib/storage/createWebStorage";

const createNoopStorage = () => {
  return {
    getItem(_key) {
      return Promise.resolve(null);
    },
    setItem(_key, value) {
      return Promise.resolve(value);
    },
    removeItem(_key) {
      return Promise.resolve();
    },
  };
};

const storage =
  typeof window === "undefined" ? createNoopStorage() : createWebStorage();

export default storage;

rokinsky avatar Jul 15 '20 10:07 rokinsky

In my case the problem was that I was trying to use the old store in other files that needed to be changed to AsyncStorage

frankpaul142 avatar Jul 20 '20 14:07 frankpaul142

The "noop" storage issue is not solved yet. After a while, uhm, almost half of the year!

vinhphamthanh13 avatar Dec 02 '20 13:12 vinhphamthanh13

What does the error mean and what does it do if it is failing to create a sync storage? Because my persistance state is working as expected.

ashley00101010 avatar Jan 09 '21 15:01 ashley00101010

Any updates on this redux-persist?

DaveMitten avatar Jan 18 '21 15:01 DaveMitten

where exactly this problem comes from ?

Gregory-Canonne avatar Feb 04 '21 11:02 Gregory-Canonne

I found out that I had an unused import storage from 'redux-persist/lib/storage' in my files that produced this error. After removing all these imports, everything work fine !

Pandazaur avatar May 07 '21 14:05 Pandazaur

In case of NextJs (or SSR based application), the issue is solved by using storage conditionally based on it is client side or server side for persisting the states. As for the matter of fact the 'window is not defined on server side'.

Example code :

const isClient = typeof window !== "undefined";

let mainReducer;
if (isClient) {
 const { persistReducer } = require("redux-persist");
 const storage = require("redux-persist/lib/storage").default;

 const rootPersistConfig = {
   key: "root",
   storage: storage,
   blacklist: ["countries"],
 };

 const countriesPersistConfig = {
   key: "countries",
   storage: storage,
   whitelist: ["countriesList"],
 };

 /* COMBINE REDUCERS */
 const combinedReducers = combineReducers({
   countries: persistReducer(countriesPersistConfig, countries),
 });

 mainReducer = persistReducer(rootPersistConfig, combinedReducers);
} else {
 mainReducer = combineReducers({
   countries,
 });
}

If it still doesn't solve the problem. Do try reading through this thread - using-redux-with-redux-persist-with-server-side-rendering

Thank you.

rishav4101 avatar Jun 29 '21 23:06 rishav4101

The same here with [email protected] :-(

Update: I am running React-Native with expo run:android on Android phone. From the backtrace it seems createWebStorage is called even though AsyncStorage is selected in config according to the info on the main project page / readme.

Update: Okay I made it work, sorry :-)

import AsyncStorage from '@react-native-community/async-storage';
import { createStore } from 'redux'
import { persistStore, persistReducer } from 'redux-persist'

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

For some reason import storage from 'redux-persist/lib/storage' // defaults to localStorage for web this line must be removed as this selects WebStorage even for a mobile application. Maybe a small improvement hint for next release? :-)

Thank you for this marvelous library! I am using it to store data in AsyncStorage and secure tokents in ExpoSecureStore (KeyChain interface). Debugging helped me to even more understand how redux actions/reducers work :-)

Have a great day! :-)

cederom avatar Aug 26 '21 20:08 cederom

import AsyncStorage from '@react-native-async-storage/async-storage'

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

is having the same issue, I look everywhere on google but none of the solutions are working

tylim88 avatar Sep 13 '21 02:09 tylim88

I'm having the same issue with 6.0.0 during SSR in dev mode. Is it possible to disable this warning when typeof window === "undefined"?

btw, here is my workaround:

import createWebStorage from "redux-persist/lib/storage/createWebStorage";

const createNoopStorage = () => {
  return {
    getItem(_key) {
      return Promise.resolve(null);
    },
    setItem(_key, value) {
      return Promise.resolve(value);
    },
    removeItem(_key) {
      return Promise.resolve();
    },
  };
};

const storage =
  typeof window === "undefined" ? createNoopStorage() : createWebStorage();

export default storage;

You have to pass an argument in createWebStorage() function. It is createWebStorage('local').

Found out here.

JusticeBringer avatar Sep 28 '21 12:09 JusticeBringer

Same issue here, any solution? Only downgrading the library seem to work.

Dragosh-lunchCo avatar Nov 18 '21 11:11 Dragosh-lunchCo

Actually setting the stateReconciler to hardSet fixes the issue!

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

Dragosh-lunchCo avatar Nov 18 '21 11:11 Dragosh-lunchCo

Actually setting the stateReconciler to hardSet fixes the issue!

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

negative, still getting the error, any more solutions to this?

jeremiahcanlas avatar Jan 14 '22 04:01 jeremiahcanlas

Anyone sort this out for AsyncStorage? Seeing the same thing after following the instructions verbadam

anwarhamr avatar Feb 13 '22 00:02 anwarhamr

I found out that I had an unused import storage from 'redux-persist/lib/storage' in my files that produced this error. After removing all these imports, everything work fine !

Good catch! I had the same thing on my end.

adamsimonini avatar Mar 30 '22 15:03 adamsimonini

I found out that I had an unused import storage from 'redux-persist/lib/storage' in my files that produced this error. After removing all these imports, everything work fine !

Good catch! I had the same thing on my end.

I had the same problem! Replaced the storage with AsyncStorage and also removed the lib/storage import. Works now!

eeshankeni avatar Mar 30 '22 15:03 eeshankeni

I found out that I had an unused import storage from 'redux-persist/lib/storage' in my files that produced this error. After removing all these imports, everything work fine !

This one work for me

saravanakumarRN avatar May 11 '22 14:05 saravanakumarRN

Solved

import { applyMiddleware } from 'redux'
import { configureStore } from '@reduxjs/toolkit'
import reducers from '../reducers/index'
import { persistStore, persistReducer } from 'redux-persist'
// import storage from 'redux-persist/lib/storage'
import storageSession from 'reduxjs-toolkit-persist/lib/storage/session'
import thunk from 'redux-thunk'

const persistConfig = {
  key: 'persist-store',
  storage : storageSession,
}


const persistedReducer = persistReducer(persistConfig, reducers)

const store = configureStore({
  reducer: persistedReducer,
  middleware: [thunk],  devTools: process.env.NODE_ENV !== 'production',
})

export const persistor = persistStore(store)

export default store;


yousuf4249 avatar Aug 16 '22 17:08 yousuf4249

@yousuf4249 Can I get a detailed solution from you? I am trying to create a Redux store with NextJs, But while I can not understand what is going wrong, I get an error in the console redux-persist failed to create sync storage. falling back to noop storage. TypeError: Cannot read properties of undefined (reading 'getState')

I tried to create something similar to what you described as a solution, but I'm clearly missing something

ArturKuzmich avatar Aug 21 '22 15:08 ArturKuzmich

@yousuf4249 Thunk middleware is provided by default in configureStore. See https://redux-toolkit.js.org/usage/usage-guide#using-middleware-to-enable-async-logic

ValentineCodes avatar Aug 24 '22 05:08 ValentineCodes

@yousuf4249 sorry for asking. perhaps you could show a code example with Redux + Nextjs + Redux persistor set up. I still couldn't save the data when changing the page in my store

ArturKuzmich avatar Aug 24 '22 09:08 ArturKuzmich

The following error is thrown when loading the page not when running the server.

redux-persist failed to create sync storage. falling back to noop storage.

REASON: The redux is only configured for the client side only. It should also be integrated to work on the server side as well.

next-redux-wrapper has not been implemented.

ge-infosec avatar Jan 10 '23 00:01 ge-infosec

const createNoopStorage = () => { return { getItem(_key: any) { return Promise.resolve(null); }, setItem(_key: any, value: any) { return Promise.resolve(value); }, removeItem(_key: any) { return Promise.resolve(); }, }; };

const storage = typeof window === "undefined" ? createNoopStorage() : require("redux-persist/lib/storage").default;

export default storage;

aaraomelo avatar May 27 '23 16:05 aaraomelo

I found out that I had an unused import storage from 'redux-persist/lib/storage' in my files that produced this error. After removing all these imports, everything work fine !

Oh my god just this one line. Thank you and it's almost 3AM already. Night night

duyrk avatar Jul 17 '23 19:07 duyrk