We’ve been switching our workflow from expo build:<platform>
to eas
builds (because we had to, to use Stripe on iOS).
It’s been a super bumpy road.
The latest issue that I’m running into is that we used to use react-native-dotenv
to manage our configurations. That works fine in development, but when we run a build, the @env module is empty.
Thinking it might be best to switch to the Constants.manifest.extra
path, since that seems to be recommended, I decided to give it a shot. So we now have an app.config.js
file which starts as follows:
We then have the following:
import 'dotenv/config';
const extraEnvs = {
EXTRA_TEST: true,
AUTH0_DOMAIN: process.env.AUTH0_DOMAIN,
AUTH0_NATIVE_CLIENT_ID: process.env.AUTH0_NATIVE_CLIENT_ID,
AUTH0_WEB_CLIENT_ID: process.env.AUTH0_WEB_CLIENT_ID,
GRAPHQL_ENDPOINT: process.env.GRAPHQL_ENDPOINT,
STORAGE_BASE: process.env.STORAGE_BASE,
SEGMENT_IOS_WRITE_KEY: process.env.SEGMENT_IOS_WRITE_KEY,
SEGMENT_ANDROID_WRITE_KEY: process.env.SEGMENT_ANDROID_WRITE_KEY,
GOOGLE_API_KEY: process.env.GOOGLE_API_KEY,
STRIPE_PUBLISHABLE_KEY: process.env.STRIPE_PUBLISHABLE_KEY,
};
console.log('@@ extraEnvs: ', extraEnvs);
export default () => {
return {
expo: {
[...]
extra: extraEnvs,
},
};
};
When our CD scripts run, I can see the extraEnvs
properly printed out, with the appropriate values per environment. But when I actually run the app? There’s nothing in there, even though it works fine in development (using --dev-client
).
As you can see, I added a testing value (EXTRA_TEST: true,
) to see what happened when I console.log
the whole manifest in the app. That one is there. But all the other variables, which console.log
during the build process, aren’t there when the app runs.
Anyone have any idea what’s going on? This switch to EAS is making me want to pull my hair out. Every time I fix something, a couple other things break.
EDIT 1:
I just noticed something. I run expo publish
during deployment to do OTA updates, before a build gets submitted to the app stores. It looks like the environment variables print out during the publish command, but when the eas
commands run, the environment variables are empty. Does app.config.js
run differently during the eas
commands? I’m not sure I understand how/why that would be the case? It’s the same js
file?
EDIT 2:
Of course, as soon as I finish writing this stuff, I think I find the culprit:
I do find it a bit frustrating that these systems seem to have diverged so much.