9

I would like to determine in react native code if the app is running in Expo Go or as a stand-alone iOS/Android app.

I can’t use __DEV__, because I would like to be able to determine this also for a production build.

pors
  • 3,856
  • 36
  • 33

2 Answers2

16

You can use Expo's AppOwnership from Constants

import Constants from 'expo-constants'

const isRunningInExpoGo = Constants.appOwnership === 'expo'

source

Ryan Soderberg
  • 585
  • 4
  • 21
  • 2
    This property appOwnership only applies to the managed workflow and classic builds; for apps built with EAS Build and in bare workflow, the result is always null – timboektoe Jan 30 '23 at 06:36
4

Since classic builds are now deprecated and everyone will start using EAS Builds, you will need to use Constants.ExecutionEnvironment instead of appOwnership which is always null in builds done via EAS.

So you could use the following to check if in production:

ExecutionEnvironment.Standalone === "standalone"

Documentation can be found here

Eduard
  • 3,395
  • 8
  • 37
  • 62
  • That should be the accepted solution ! One question, what is the meaning of "bare" ? Will it be always "standalone" on production mode ? – Julien Pepe Feb 17 '23 at 20:39
  • So, `bare` is for projects that have "ejected". Which means, they run on all the same expo code, but the developer has access to things like the compiled source code for ios, android, and so on. Just like you would "eject" a normal react app to get access to metro. You will almost never need bare, unless you want something very specific, given they released `expo-dev-client` which allows you to add custom native libraries via configuration plugins, like `stripe-react-native` or `react-native-track-player` – Eduard Feb 17 '23 at 23:38
  • Ok thank you, but I have a managed workflow, and in my expo dev client app, when I console.log the Constants value, it show my "bare" for the execution environnement. So that's weird – Julien Pepe Feb 18 '23 at 09:41
  • 1
    @JulienPepe That is correct, because you're using the expo-dev-client. So, `standalone` is for a production build, `storeClient` is when you develop through the `Expo Go` client, and `bare` is when you develop through your own app (either via ejection, or via the dev-client, as it's basically a "simulator" of bare setup). – Eduard Feb 18 '23 at 11:50
  • correct check would be: `import Constants, { ExecutionEnvironment } from 'expo-constants'` `Constants.executionEnvironment === ExecutionEnvironment.Standalone` – Nazar Aug 18 '23 at 13:01
  • I've been building the app using `eas build --platform ios` for prod and `eas build --profile development-simulator --platform ios` for dev. Unfortunately `Constants.executionEnvironment` returns `bare` for both. Any idea why this happens? – ElDiabolo Sep 01 '23 at 08:15
  • @Nazar are you running on the bare workflow or managed (eg. Did you eject?) if you did, that is your answer – Eduard Sep 02 '23 at 10:23