react-native-async-storage / async-storage

An asynchronous, persistent, key-value storage system for React Native.
https://react-native-async-storage.github.io/async-storage/
MIT License
4.61k stars 458 forks source link

ReferenceError: window is not defined #1056

Closed JehhB closed 5 months ago

JehhB commented 5 months ago

What happened?

I am following the documentation on how to use supabase auth in react native expo app and did what the documentation say. But when I started expo using npx expo start --web it produces this error after bunding then expo would stop. image It works fine on android tho.

Version

1.21.0

What platforms are you seeing this issue on?

System Information

System:
  OS: Windows 11 10.0.22621
  CPU: (4) x64 Intel(R) Core(TM) i7-4600U CPU @ 2.10GHz
  Memory: 4.31 GB / 11.88 GB
Binaries:
  Node:
    version: 20.5.1
    path: C:\Program Files\nodejs\node.EXE
  Yarn: Not Found
  npm:
    version: 10.4.0
    path: C:\Program Files\nodejs\npm.CMD
  Watchman: Not Found
SDKs:
  Android SDK: Not Found
  Windows SDK: Not Found
IDEs:
  Android Studio: AI-231.9392.1.2311.11255304
  Visual Studio:
    - 17.8.34511.84 (Visual Studio Community 2022)
Languages:
  Java:
    version: 1.8.0_392
    path: C:\Program Files\Eclipse Adoptium\jdk-8.0.392.8-hotspot\bin\javac.EXE
  Ruby: Not Found
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.73.2
    wanted: 0.73.2
  react-native-windows: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: Not found
  newArchEnabled: Not found
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

Steps to Reproduce

My code is

export const supabase = createClient( process.env.EXPO_PUBLIC_SUPABASE_URL!, process.env.EXPO_PUBLIC_SUPABASE_ANON_KEY!, { auth: { storage: AsyncStorage, autoRefreshToken: true, persistSession: true, detectSessionInUrl: false, }, }, );

JehhB commented 5 months ago

The problem is actually expo router with output set to static as I think it is doing some pre-rendering of somesort. I fixed it by setting the output to single. It would be nice to be still output to static site, but I am closing this issue because I think it is more of an expo-router/metro problem.

gregamann commented 4 months ago

Thanks @JehhB ! You've saved me a lot of time ! Have you opened an issue on the Expo repo?