I’ve been trying to configure my ejected expo project to work, and there’s just one final aspect I’m currently missing.
Right now, I’m using expo-constants
to define some of our app’s values that change according to the environment, like so:
import Constants from 'expo-constants'
Constants.manifest.extra.baseUrl
And these values are defined inside my app.config.js
, just like what’s suggested in the documentation:
// app.config.js
export default {
expo: {
// ...The rest of my app configuration
extra: {
baseUrl: 'my-value'
}
}
}
Now, having 'my-value'
hard-coded there works, but the problem arises when I try to follow this part of the documentation, which basically uses the dotenv
package to load values from a .env
file inside process.env
while building the app.
My current configuration is basically a .env
file that contains BASE_URL=my-base-url
, and my app.config.js has this additional configuration:
import dotenv from 'dotenv';
dotenv.config({ path: '.env' });
export default {
expo: {
// ...The rest of my app configuration
extra: {
baseUrl: process.env.BASE_URL
}
}
}
This configuration worked in both operating systems on the managed workflow, and on the bare workflow it works just fine on android. The problem arises on iOS, where I can’t seem to find a way for the app.config.js file to read from process.env (Hard-coded values are read fine with Constants.manifest.extra
, but values loaded from process.env
, like baseUrl, are undefined).
I’m not really sure how to debug from here, I’ve tried forcing my babel.config.js
to load my .env file via the inline-dotenv
package, but that doesn’t seem to be working either.
Is there a way for me to access these environment variables in the iOS app? Even if it has to be done directly via process.env
and not via Constants.manifest.extra
, I need some way to define variables based on the environment the app is being build on.