react-native-config: Not working with RN 0.60.4

The library is not working with RN 0.60.4, automatic linking is not working. If I try to link manually, it throws errors. On pod install it produces error 'GeneratedDotEnv.m' file not found.

Any help? šŸ†˜

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 42
  • Comments: 50 (2 by maintainers)

Most upvoted comments

@Elvinra that worked for me!!

Another fix, if you install with npmjs, then yarn add react-native-config Open podfile and add

post_install do |installer|
 installer.pods_project.targets.each do |target|
   if target.name == 'react-native-config'
     phase = target.project.new(Xcodeproj::Project::Object::PBXShellScriptBuildPhase)
     phase.shell_script = "cd ../../"\
     " && RNC_ROOT=./node_modules/react-native-config/"\
     " && export SYMROOT=$RNC_ROOT/ios/ReactNativeConfig"\
     " && ruby $RNC_ROOT/ios/ReactNativeConfig/BuildDotenvConfig.ruby"
     
     target.build_phases << phase
     target.build_phases.move(phase,0)
   end
 end
end

cd iOS && pod install

Here is the guide for some poor soul javascript dev like me out there:

  1. yarn add luggit/react-native-config#master (don’t use the version on npm or you will spend way too much time to figure out how this work) Note: if you want to anchor your version then use this commit instead of master https://github.com/luggit/react-native-config/commit/1eb6ac01991210ddad2989857359a0f6ee35d734
  2. Follow exactly like the README, you don’t need to add any code inside your Podfile After pod install there will be some warning like this [!] react-native-config has added 1 script phase. (which mean you are doing this right) 2a. If your want to support Info.plist, replace __RN_CONFIG_xxx to $(xxx) inside your Info.plist file
  3. Build and run your project like normal

On the side note, the README should be restructure for it is very confusing

What worked for me now on 0.60.4, inspired by @Mlobaievskyi and @s123121 -

  1. Change react-native-config ver to master "react-native-config": "github:luggit/react-native-config#master" or lock commit to 1eb6ac0 as @s123121 said. Then npm install it
  2. Follow the steps here to manually link the packageĀ https://facebook.github.io/react-native/docs/linking-libraries-ios.html#manual-linking
  3. And then put the following intoĀ react-native.config.jsĀ at root folder (Not sure if necessary)
module.exports = {
  dependencies: {
    'react-native-config': {
      platforms: {
        ios: null
      }
    }
  }
}
  1. Remember to remove this snippet fromĀ Podfile
post_install do |installer|
 installer.pods_project.targets.each do |target|
   if target.name == 'react-native-config'
     phase = target.project.new(Xcodeproj::Project::Object::PBXShellScriptBuildPhase)
     phase.shell_script = "cd ../../"\
     " && RNC_ROOT=./node_modules/react-native-config/"\
     " && export SYMROOT=$RNC_ROOT/ios/ReactNativeConfig"\
     " && ruby $RNC_ROOT/ios/ReactNativeConfig/BuildDotenvConfig.rb"
     
     target.build_phases << phase
     target.build_phases.move(phase,0)
   end
 end
end

and the lineĀ pod 'react-native-config', :path => '../node_modules/react-native-config' then runĀ pod install again (To be safe you can delete Podfile.lock first)

Then I was getting 'GeneratedDotEnv.m' file not found. error After battling it a while I realized from this PR (https://github.com/luggit/react-native-config/commit/1eb6ac01991210ddad2989857359a0f6ee35d734) that I should remove all these preprocess settings. After that 'GeneratedDotEnv.m' file not found. error is gone and it works for me. image

You are using react-native-config from npmjs, try to use this librairy directly from github yarn add https://github.com/luggit/react-native-config

Can we have a new release from master? I don’t feel comfortable hardcoding a repository link in my package.json.

@ninjz you are correct remember that choose your target for Provide build settings form Screen Shot 2019-07-30 at 1 41 46 PM

What I’m doing for RN 0.60.4 (Upgraded from 0.59.9) is basically

  1. Change react-native-config ver to master "react-native-config": "github:luggit/react-native-config#master" or lock commit to 1eb6ac0 as @s123121 said. Then npm install it
  2. (if exists) Remove pod 'react-native-config', :path => '../node_modules/react-native-config' in Podfile
  3. (if exists) Remove the package link at Link Binary with libraries in your XCode Workspace
  4. Add the following to Podfile, notice that it’s .rb instead of .ruby for me (Thanks @mchudy)
post_install do |installer|
 installer.pods_project.targets.each do |target|
   if target.name == 'react-native-config'
     phase = target.project.new(Xcodeproj::Project::Object::PBXShellScriptBuildPhase)
     phase.shell_script = "cd ../../"\
     " && RNC_ROOT=./node_modules/react-native-config/"\
     " && export SYMROOT=$RNC_ROOT/ios/ReactNativeConfig"\
     " && ruby $RNC_ROOT/ios/ReactNativeConfig/BuildDotenvConfig.rb"
     
     target.build_phases << phase
     target.build_phases.move(phase,0)
   end
 end
end
  1. run pod install at ios folder

But I’m getting this now, anyone knows why?

/Users/kaiden-dragon/dev/dragon-frontend/react-native/node_modules/react-native-config/ios/ReactNativeConfig/ReadDotEnv.rb:27:in `join': no implicit conversion of nil into String (TypeError)
	from /Users/kaiden-dragon/dev/dragon-frontend/react-native/node_modules/react-native-config/ios/ReactNativeConfig/ReadDotEnv.rb:27:in `read_dot_env'
	from ./node_modules/react-native-config//ios/ReactNativeConfig/BuildDotenvConfig.rb:15:in `<main>'
reading env file from  and writing .m to 
going to read env file from root folder 
Command PhaseScriptExecution failed with a nonzero exit code

@fariasmark Try replacing BuildDotenvConfig.ruby with BuildDotenvConfig.rb. It helped in my case.

@Elvinra that worked for me!!

Another fix, if you install with npmjs, then yarn add react-native-config Open podfile and add

post_install do |installer|
 installer.pods_project.targets.each do |target|
   if target.name == 'react-native-config'
     phase = target.project.new(Xcodeproj::Project::Object::PBXShellScriptBuildPhase)
     phase.shell_script = "cd ../../"\
     " && RNC_ROOT=./node_modules/react-native-config/"\
     " && export SYMROOT=$RNC_ROOT/ios/ReactNativeConfig"\
     " && ruby $RNC_ROOT/ios/ReactNativeConfig/BuildDotenvConfig.ruby"
     
     target.build_phases << phase
     target.build_phases.move(phase,0)
   end
 end
end

cd iOS && pod install

I had to replace that last line with:

" && ruby $RNC_ROOT/ios/ReactNativeConfig/BuildDotenvConfig.rb \"${SRC_ROOT}/../\" \"${SYMROOT}\""

I need help! I’ve try @dineshmm23’s solution but I’m still getting this error:

ruby: No such file or directory – ./node_modules/react-native-config//ios/ReactNativeConfig/BuildDotenvConfig.ruby (LoadError)

Command PhaseScriptExecution failed with a nonzero exit code

@Mlobaievskyi That’s so wierd lol I’m still trying to figure out this error

/Users/kaiden-dragon/dev/dragon-frontend/react-native/node_modules/react-native-config/ios/ReactNativeConfig/ReadDotEnv.rb:27:in `join': no implicit conversion of nil into String (TypeError)
	from /Users/kaiden-dragon/dev/dragon-frontend/react-native/node_modules/react-native-config/ios/ReactNativeConfig/ReadDotEnv.rb:27:in `read_dot_env'
	from ./node_modules/react-native-config//ios/ReactNativeConfig/BuildDotenvConfig.rb:15:in `<main>'
reading env file from  and writing .m to 
going to read env file from root folder 
Command PhaseScriptExecution failed with a nonzero exit code

I’m using react-native-config 1.4.1 and was running into the empty object problem on ios so I added a new run script within Build Phases and got the config correctly populated as expected:

Update:

cd "$SRCROOT/../"
RNC_ROOT_DIR=$(pwd)
cd -

echo "Setting env for configuration: ${CONFIGURATION} with root dir: ${RNC_ROOT_DIR}"

if [ "${CONFIGURATION}" = "Release" ]; then
    echo "$RNC_ROOT_DIR/.env.production" > /tmp/envfile
    "$RNC_ROOT_DIR/node_modules/react-native-config/ios/ReactNativeConfig/BuildDotenvConfig.rb" "$RNC_ROOT_DIR/.env.production" "$RNC_ROOT_DIR/node_modules/react-native-config/ios/ReactNativeConfig"
else
    echo "$RNC_ROOT_DIR/.env.development" > /tmp/envfile
    "$RNC_ROOT_DIR/node_modules/react-native-config/ios/ReactNativeConfig/BuildDotenvConfig.rb" "$RNC_ROOT_DIR/.env.development" "$RNC_ROOT_DIR/node_modules/react-native-config/ios/ReactNativeConfig"
fi

Create a new run script and paste the above in there. Update your .env files within the script above accordingly. I’m using .env.production and .env.development for release and debug builds respectively.

Screen Shot 2020-12-07 at 11 45 07 PM

In order to change between debug and release builds you can go to ā€œEdit schemesā€ for your target:

Screen Shot 2020-12-07 at 11 33 20 PM copy

And select between the 2 builds:

Screen Shot 2020-12-07 at 11 33 53 PM

The next build and run of your app should contain the contents between your various env files.

post_install do |installer|
 installer.pods_project.targets.each do |target|
   if target.name == 'react-native-config'
     phase = target.project.new(Xcodeproj::Project::Object::PBXShellScriptBuildPhase)
     phase.shell_script = "cd ../../"\
     " && RNC_ROOT=./node_modules/react-native-config/"\
     " && export SYMROOT=$RNC_ROOT/ios/ReactNativeConfig"\
     " && ruby $RNC_ROOT/ios/ReactNativeConfig/BuildDotenvConfig.ruby"
     
     target.build_phases << phase
     target.build_phases.move(phase,0)
   end
 end
end

THIS WORKS!!!

Found solution

  1. yarn add react-native-config
  2. manually link https://facebook.github.io/react-native/docs/linking-libraries-ios.html#manual-linking
  3. add next to react-native.config.js
module.exports = {
  dependencies: {
    'react-native-config': {
      platforms: {
        ios: null
      }
    }
  }
}
  1. react-native run-ios (archive also work)

I just upgraded my React Native version to 0.61.4 and react-native-config ^0.12.0. @kdenz solution worked for me.

I’m also having some trouble with getting RN0.60.4 to work with this library. I get an error in the preprocessing Info.plist

GeneratedInfoPlistDotEnv.h' file not found

It seems like there’s so many different fixes each for different versions and if people have multiple envs.

Can we get some way of version controlling each solution and have an updated example. (it’s currently at RN50). Perhaps just having a proper example for each version will alleviate all the issues popping up because this library doesn’t work with this version.

@Elvinra that worked for me!!

Another fix, if you install with npmjs, then yarn add react-native-config Open podfile and add

post_install do |installer|
 installer.pods_project.targets.each do |target|
   if target.name == 'react-native-config'
     phase = target.project.new(Xcodeproj::Project::Object::PBXShellScriptBuildPhase)
     phase.shell_script = "cd ../../"\
     " && RNC_ROOT=./node_modules/react-native-config/"\
     " && export SYMROOT=$RNC_ROOT/ios/ReactNativeConfig"\
     " && ruby $RNC_ROOT/ios/ReactNativeConfig/BuildDotenvConfig.ruby"
     
     target.build_phases << phase
     target.build_phases.move(phase,0)
   end
 end
end

cd iOS && pod install

Thanks. It works

Chiming in here because this issue was invaluable in helping me to upgrade to 0.60.5 (and at this point I have this working in plist and in javascript):

If you remove preprocessor settings, don’t expect any variables in your plist file to work. I did this because I simply needed my app to build so I could move onto other dependencies.

If you want to use variables in your plist and need to remove the preprocessor steps to get your app to run, make sure to follow @s123121’s steps above.

NOTE: the readme is different from comments here that I’ve gotten to work, specifically the line: ${SRCROOT}/../node_modules/react-native-config/ios/ReactNativeConfig/BuildXCConfig.rb "${SRCROOT}/.." "${SRCROOT}/tmp.xcconfig"

The README has the first operation in quotes which wasn’t getting there for me, when I used the one posted by @ninjz this finally worked.

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

@mehdihz npm version?

I ended up using this specific commit and then I didn’t need the post-install scripts mentioned in other issues github.com/luggit/react-native-config.git#89a602b

Can’t seem to get this running either. Followed various options from above and none have worked. Got the same error as @kdenz when I tried his one.

I’ll see if I can get it going with a react-native init and see if I can figure out what’s going on from there.