Hey folks,
Just upgraded my project to react-native 0.62.1
In addition, I migrated react-native-config from 0.11.5 all the way to 1.0.0
I've updated my info.plist variables to match the new formatting, removed the old pre-processing scripts, added my build pre-actions copy and xcconfig setup. I believe my info.plist is actually pulling in variables properly, huzzah!
However, inside my actual JS, my Config

Is giving me a blank object.
I'm still loading in the envfiles the exact same way as before.

If other folks upgrading are experiencing this, or if anyone has direction for me, it would be hugely appreciate.
Hi @ahartzog Do you have a reproducible demo?
@luancurti I do not, unfortunately other demands on my time mean I can't spin up a brand new 0.62 and re-create this
If this issue is common as people upgrade to 0.62, I'd like to see where we land. If it isn't, then I'll just have to find which esoteric hidden mis-configuration in my project is causing the issue.
Thank you for the response!
RN 0.62.2
react-native-config 1.0.0
I managed to solve it by deleting this workaround https://github.com/luggit/react-native-config/issues/414#issuecomment-559014103 and deleting workaround in Podfile
```
installer.pods_project.build_configurations.each do |config|
if config.name == 'Staging'
config.build_settings['CONFIGURATION_BUILD_DIR'] = '$(BUILD_DIR)/Release$(EFFECTIVE_PLATFORM_NAME)'
end
end
Then I run `react-native link && cd ios && pod install`.
Then I cleaned project. Also I disabled Info.plist preprocessing in Build Settings -> Packaging -> Preprocess Info.plist File.
Also I have this in my android/app/build.gradle
project.ext.envConfigFiles = [
releasestaging: ".env.staging",
release: ".env.production",
anycustombuildlowercase: ".env",
]
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"
```
@ahartzog try to remove envfile from /tmp directory.
On mac go to Finder -> Go -> Go to Folder -> /tmp
The ruby script tries to find env file firstly from _tmp/envfile_. Then if it doesn't find anything searches in _ENVFILE_ variable.
Hope this helps
@makarkotlov good call on clearing out the react-native-config, I had forgotten to do that when updating from manual linkage.
Running the link on it isn't changing anything in the iOS config for me (and autolinking should work right in theory, according to @luancurti in another post)
I'm still not seeing my env variables in my JS - I've noticed that the pre-build script

Creates that envfile inside private/tmp - and then I still have no idea what this file is supposed to be doing or pointing to. Should I point it to my actual env file with an "absolute" url e.g.

Somebody mentioned that this file just works as a pointer to the actual file - I've also tried deleting it like the prior poster mentions but as far as I can tell this has no effect.
Still trying to figure this out here - would appreciate any additional ideas.
I went ahead and tried @maxkomarychev 's new library, react-native-ultimate-config.
So far so good, iOS worked easily. Android fired up like a charm once I removed all the manual crap I had in place from RNC. JS config works, build configs work.
I would consider moving back to this when it's actually a part of react-native-community and supported, but until then I'll be with RNUC.
I am facing issue in reading the config value it is undefined on reading Config.API_URL with the import Config from "react-native-config";
RN 0.61.5
react-native-config 1.0.0
Only issue is with Ios and works fine with Android platform
I am facing issue in reading the config value it is undefined on reading Config.API_URL with the import Config from "react-native-config";
RN 0.61.5
react-native-config 1.0.0Only issue is with Ios and works fine with Android platform
Could you please give us more info?
How many .env files do you have?
Do you use pre-action script?
Could you please check content of your tmp/envfile on your PC / Mac ?
I am facing issue in reading the config value it is undefined on reading Config.API_URL with the import Config from "react-native-config";
RN 0.61.5
react-native-config 1.0.0
Only issue is with Ios and works fine with Android platformCould you please give us more info?
How many .env files do you have?
Do you use pre-action script?
Could you please check content of yourtmp/envfileon your PC / Mac ?
i had to restart my machine, it works for me.
For me (RN0.62.2 + v1.0.0), it's not that the config is empty - it's returning the contents of my react-native-config.js, not my .env file...
js
import Cfg from 'react-native-config';
console.warn('CONFIG', Cfg);
prints:
'CONFIG', { dependencies: { 'react-native-flipper': { platforms: { ios: null } } } }
I suspect it's loading this.
EDIT:
js
// iOS:
import Cfg from 'react-native-config'; // Returns react-native-config.js contents.
import Cfg from 'react-native-config/index'; // Returns .env file contents.
馃く
@wbercx But the file with dependencies you've mentioned is called react-native.config.js. Not react-native-config.js.
@wbercx But the file with dependencies you've mentioned is called
react-native.config.js. Notreact-native-config.js.
馃う You're absolutely right. Thanks for pointing that out.
It's been a while since one character cost me this much time haha.
If you are using Pods just add (without react-native link react-native-config)
pod 'react-native-config', :path => '../node_modules/react-native-config/react-native-config.podspec'
in your Podfile
I installed the package according to the instructions, and it worked... for a while. After switching branches, with code changes, etc., the config started returning an empty object.
I tried reinstalling modules and pods, clearing the cache, in the end I got the config data, only writing explicitly
echo ".env" > /tmp/envfile
Hello, I'm having the same problem with the latest version, but for Android on Windows.
OS - Windows 10 Pro 64-bit
Node - 12.16.3
RN - 0.62.2
react-native-config - v1.2.0
I've tried everything in the documentation and supposed fixes from random issues.
React-native-config v1.1.0 works, v1.2.0 returns an empty object.
Anyone else having this issue?
Edit:
Ok, so a colleague downloaded and sent me the 1.2.0 package, now it returns the env. variables, instead of an empty object. He too is with Win10 Pro, Node 12.16.3. 馃
Unless I name one of my files to .env I'm also getting an empty Config on iOS.
react-native: 0.61.5
react-native-config:1.2.1
I was able to get it to work by changing the Pre-action Build script to:
echo ".env.stage" > /tmp/envfile
echo ".env.stage" > /tmp/envfile
@MattyK14 Thanks that worked for me!
The README.md instructions seem to be misleading on this one. While at one point it mentions the tmp/envfile in step 6 of the iOS setup, the actual iOS Multi-Scheme section instructs us to use cp ${PROJECT_DIR}/../.env.staging .env as pre-action.
However, I could not get the pre-action work using the cp command. Switching the command to echo ".env.stage" > /tmp/envfile as suggested before works perfectly.
IOS:
[email protected]
[email protected]
this in pre-action worked for me
echo ".env.staging" > .env
this not:
echo ".env.staging" > /tmp/envfile
update:
see comment below
I have installed react-native-config according to docs and I have empty config.
Sure, echo ".env.staging" > /tmp/envfile - fix this issue.
but why we have such a case?
so I have to correct something
it's very strange sometimes it works sometimes not.
for 9 days this worked:
echo ".env.staging" > .env
for 2 days this worked
cp ${PROJECT_DIR}/../.env.staging .env
and yesterday no one of the above commands worked:
also not this:
echo ".env.staging" > /tmp/envfile
I think the pre-actions are being executed too late,
because on the second run it works sometimes
at the moment i'm copying my stage env variables manually into .env
Hello guys!
I am having this exact same issue with react-native 0.63.2 and react-native-config 1.3.2.
Is there a workarround for this?
Cannot make it work on iOS, Android works fine
Thanks!
My problem was that I mistakenly added echo ".env.staging" > /tmp/envfile to the Run scripts. When changed to use Build scripts instead got this to work.
(Could not get the more clean cp ${PROJECT_DIR}/../.env.staging .env version to work, though.)
@ronkot Thanks for your reply, I have already tried that without success :(
My project structure is
root/.env
root/.env.production
root/ios/etc
root/android/etc
Should I write
echo ".env.production" > /tmp/envfile
or
echo "../.env.production" > /tmp/envfile
?
Works for me too.
echo ".env.production" > /tmp/envfile
But to change the info.plist information like the display name I've created two different targets, I couldn't read any entry of the config...
I ended up using the following, since I only need them to be visible on the React Native (JS) side.
staging.json
production.json
scripts/set-environment.js
#!/bin/node
const fs = require('fs');
//Obtain the environment string passed to the node script
const environment = process.argv[2];
//read the content of the json file
const envFileContent = require(`../envs/${environment}.json`);
//copy the json inside the env.json file
fs.writeFileSync('env.json', JSON.stringify(envFileContent, undefined, 2));
Finally, I call staging or prod depending on the case
node scripts/set-environment.js staging
node scripts/set-environment.js production
same error here with the solution from the docs
I was wondering if anyone found a potential fix.
Still having the issue of the empty config file after following the official documentation in step number 6 (iOS).
React Native v0.63.2
React Native Config v1.3.3
I was having this issue today but i was getting values had changed in my .env file. The only way to get the proper env vars was to delete everything in /tmp (mac os) and recompile the app. Now it works.
Make sure you remove /tmp/envfile if you've changed from the old echo method to the new cp one. I was pulling my hair out trying to figure out why and it turns out the Ruby file still checks for /tmp/envfile https://github.com/luggit/react-native-config/blob/master/ios/ReactNativeConfig/ReadDotEnv.rb#L15
Most helpful comment
I went ahead and tried @maxkomarychev 's new library, react-native-ultimate-config.
So far so good, iOS worked easily. Android fired up like a charm once I removed all the manual crap I had in place from RNC. JS config works, build configs work.
I would consider moving back to this when it's actually a part of react-native-community and supported, but until then I'll be with RNUC.