Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not working react native web #1096

Open
1 of 5 tasks
adsalihac opened this issue May 30, 2024 · 16 comments
Open
1 of 5 tasks

not working react native web #1096

adsalihac opened this issue May 30, 2024 · 16 comments
Labels
bug Something isn't working

Comments

@adsalihac
Copy link

adsalihac commented May 30, 2024

What happened?

Getting Error

Version

1.23.1

What platforms are you seeing this issue on?

  • Android
  • iOS
  • macOS
  • Windows
  • web

System Information

Error storing data ReferenceError: window is not defined
    at getValue (/node_modules/@react-native-async-storage/async-storage/lib/commonjs/AsyncStorage.js:69:52)

Steps to Reproduce

  • install async storage in expo 51
  • run web
@adsalihac adsalihac added the bug Something isn't working label May 30, 2024
@t1gu1
Copy link

t1gu1 commented Jun 1, 2024

Got the exact same issue.
Using the latest expo release and start the dev for the web.

@TheForgetTime
Copy link

TheForgetTime commented Jun 2, 2024

Got the exact same issue.

Using:
"expo": "^51.0.9"
"@react-native-async-storage/async-storage": "1.23.1"
"redux-persist": "^6.0.0"

@t1gu1
Copy link

t1gu1 commented Jun 4, 2024

Here's a workaround if you are using something like Zustand:

// Zustand Store
{
      ...,
      storage: createJSONStorage(() =>
        Platform.OS === "web" ? localStorage : AsyncStorage
      ),
      ...,
}

@adsalihac
Copy link
Author

localStorage ?

@coren-frankel
Copy link

coren-frankel commented Jun 6, 2024

For those using supabase and seeing this in the stack trace too, check out supabase/supabase-js#786

@t1gu1
Copy link

t1gu1 commented Jun 6, 2024

localStorage ?

@adsalihac
Yep, in web localStorage it's simply the native solution. (No even need to import anything to use it)

At least, Zustand is able to deal with that seamlessly.

@adsalihac
Copy link
Author

adsalihac commented Jun 6, 2024

i am using redux with presist , it is support ? @t1gu1 , also what about Zustand , it is better than redux ?

@t1gu1
Copy link

t1gu1 commented Jun 6, 2024

@adsalihac Nope Redux is more complexe on that side.
That being said, for you question I would 100% recommend Zustand if you just started your project!

We migrate all our project to use Zustand cause it's stupid easy to use and works really well!
It makes look Redux over complicated for nothings.

@adsalihac
Copy link
Author

what about state migration in zustand (like version update) , which zustand is using , official module right ?

it is possible to get data like this (store.getState()?.auth?.user) ?

@t1gu1
Copy link

t1gu1 commented Jun 7, 2024

@adsalihac Yes and yes.
Just try it. ;)

@adsalihac
Copy link
Author

Thank you @t1gu1

@samkk
Copy link

samkk commented Jun 13, 2024

I think I encountered the same problem.
can I help me,please

Using:
"expo": "~51.0.8",
"@react-native-async-storage/async-storage": "1.23.1",
"zustand": "^4.5.2",

ios error message [ReferenceError: Can't find variable: localStorage]

@t1gu1
Copy link

t1gu1 commented Jun 17, 2024

Upgrade Expo package: (Just to be sure)

  • "expo": "~51.0.13",

Where you create your Zustand store, simply add that for the storage:
#1096 (comment)

Use AsyncStorage for mobile and localStorage for the web.

@azakharchenko-msol
Copy link

Confirmed the same issue
use this code as workaround

    if (Platform.OS === 'web') {
      while (typeof window === 'undefined') {
        await new Promise(resolve => setTimeout(resolve, 100));
      }
    }

@t1gu1
Copy link

t1gu1 commented Aug 23, 2024

For me it seems like this issue can be close.
I works fine now using only AsyncStorage.
Feels like it was a Expo issue.

@sydro
Copy link

sydro commented Sep 22, 2024

some issue here with 2.0.0 version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants