While writing a simple react native application using expo i stumpled upon some issues testing my application on different environtments, while the application is in development phase.
it seemed that using sudo while starting expo is a bad idea, because you never give the same permission to expo letting you testing your app via Expo Go in administrator mode.
The problem with using sudo and resetting the Expo state file is that it mixes two different concerns
- permissions
- application state
One of the more frustrating parts of working with Expo is that permission problems can appear in places you do not expect. If you start the dev server with sudo, Expo may write cache and state files under ~/.expo as root. That leaves the project in a state where your normal user account cannot access the same files, causing startup and reload issues. The better approach is to fix the ownership of those files and restart Expo without sudo.
i managed to make it work in an android emulator, but kept getting following error while testing the application via Expo Go
java.io.IOExcepption: uncaught error
Implementation details
what i started to do is to make sure my .expo directory existed and removing existing state.json file by running following commands
mkdir -p ~/.expo
chown -R "$(whoami):$(id -gn)" ~/.expo
chmod -R u+rwX ~/.expo
to make sure i had the correct permission in .expo folder
afterwards i made sure to reset the state in expo folder by removing the generate state file by expo
rm -f ~/.expo/state.json
after that i could start my app both on the emulator and via Expo.
npx expo start -c
Conclusion
The importance of this issue is following
- sudo may solve a temporary error,
- but can leave behind a broken local environment
- and the real fix is to restore correct file ownership and run the tool as the normal user.