Skip to content

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

Answered by rokinsky
hpachy asked this question in Help
Discussion options

You must be logged in to vote

This log occurs on the server-side (when you import storage from redux-persist/lib/storage) because you cannot create the local storage in Node.js. 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" ? createWebStorage("local") : createNoopStorage();

export default storage;

Use this storage in the config instead of redux-persist/lib/storage

Replies: 9 comments 25 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
18 replies
@alim-ansari
Comment options

@mrjackyliang
Comment options

@ajaykumareminence
Comment options

@sumit-6
Comment options

@noyonalways
Comment options

Answer selected by hpachy
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@Raghunadh9
Comment options

@ajaykumareminence
Comment options

Comment options

You must be logged in to vote
4 replies
@GustinDev
Comment options

@ManojThulung
Comment options

@tareq-mahmood-sazim
Comment options

@sayedulkrm
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@abhishek98s
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet