I'm stil using react-native-scripts and have not ejected, so I can't add custom gradle scripts. Should react-native-config still work, and do I need to set up something so that it works with the Expo app? I'm currently just getting an empty object for Config.
@Yogu I get the same thing. It doesn't seem to be working.
Same result here. Since it requires react-native link react-native-config I don't think it'll ever work with Expo unless we eject from Expo 🤷♂️
For reference I got my .env to work with the following:
babel-plugin-inline-dotenv to devDependencies:$ npm install --save-dev babel-plugin-inline-dotenv
inline-dotenv to .babelrc:{
"plugins": ["inline-dotenv"]
}
.env file:HELLO_WORLD="Hello, world!"
<Text style={styles.getStartedText}>{process.env.HELLO_WORLD}</Text>
Only real caveat is the React Native packager needs to be restarted between .env changes, either the hot-reloading isn't watching .env or babel doesn't run between hot-loading. Either way I'm happy with that as I'll be using .env to override config options in my app 🎉
I've spent a couple of hours trying to get @jdrydn's solution above to work, and to no avail. Seems everyone else has managed to though, so no idea why it's not working for me.
exp start as needed for notification setupbabel-plugin-inline-dotenv and dotenv (and tried without dotenv installed too), both options haven't workednode_modules and package_lock.jsonyarn, then removed and installed with npminline-dotenv to .babelrc inside env.development as well as at the rootCurrent .babelrc:
{
"presets": ["babel-preset-expo"],
"env": {
"development": {
"plugins": ["transform-react-jsx-source","inline-dotenv"]
}
},
"plugins": ["inline-dotenv"]
}
Are there any steps I'm missing that aren't listed above? I'm at the end of myself here, I just want to use environment variables I can't believe I've spent half a day on this and it still doesn't work 😞
EDIT: Wow ok, so outputting process.env will just have { "NODE_ENV": "development" } but outputting process.env.HELLO_WORLD works (though it didn't when I first tried out my setup)
Make sure to output the specific ENV var, not the whole process.env folks.
I ejected from Expo. It works on the Java side, but the Javascript Config object remains empty
Fixed it by adding resValue "string", "build_config_package", "host.exp.exponent" per the documentation.
inline-dotenv plugin is working for me as described above. However every time I change the .env file I have to restart server and clean the cache by passing -c flag (otherwise the configuration won't change):
yarn start -c
Most helpful comment
Same result here. Since it requires
react-native link react-native-configI don't think it'll ever work with Expo unless weejectfrom Expo 🤷♂️For reference I got my
.envto work with the following:babel-plugin-inline-dotenvtodevDependencies:inline-dotenvto.babelrc:.envfile:Only real caveat is the React Native packager needs to be restarted between
.envchanges, either the hot-reloading isn't watching.envor babel doesn't run between hot-loading. Either way I'm happy with that as I'll be using.envto override config options in my app 🎉