react-nativeexpoasyncstorage

AsyncStorage in Expo/Web cannot find "window"


Trying to reproduce the supabase/native example:

https://supabase.com/docs/guides/getting-started/tutorials/with-expo-react-native

when I start up an expo app in web mode I get the following error:

% npm run web

> eatyourfriend@1.0.0 web
> expo start --web

...

› Web is waiting on http://localhost:8081

› Using Expo Go
› Press s │ switch to development build

.... › Press o │ open project code in your editor

› Press ? │ show all commands

Logs for your project will appear below. Press Ctrl+C to exit.
Server Bundling complete 5419ms (node_modules/expo-router/node/render.js)
Server Bundling complete 1748ms (node_modules/expo-router/node/render.js)
Web Bundling complete 5628ms (node_modules/expo-router/entry.js)
Web Bundling complete 1967ms (node_modules/expo-router/entry.js)
"shadow*" style props are deprecated. Use "boxShadow".
selectable prop is deprecated. Use styles.userSelect.
editable is deprecated. Use readOnly.
TouchableOpacity is deprecated. Please use Pressable.
accessibilityDisabled is deprecated.
accessibilityRole is deprecated. Use role.
focusable is deprecated.
ReferenceError: window is not defined
    at getValue (/Users/dave/Documents/repos/eatyourfriend/node_modules/@react-native-async-storage/async-storage/lib/commonjs/AsyncStorage.js:63:26)
    at /Users/dave/Documents/repos/eatyourfriend/node_modules/@react-native-async-storage/async-storage/lib/commonjs/AsyncStorage.js:39:21

Solution

  • While this does not only fix this bug, but changes your web project from static generated pages to a single page application (SPA), this does fix it:

    You can find more about the output options in the expo docs:

    AsyncStorage in Expo/Web cannot find "window"