lugg / react-native-config

Bring some 12 factor love to your mobile apps!
MIT License
4.84k stars 656 forks source link

Config is empty after upgrade to RN 0.71 #777

Closed gimi-anders closed 11 months ago

gimi-anders commented 1 year ago

react-native: 0.71.13 react-native-config: 1.5.1

After upgrading react-native from 0.70.9 to 0.71.13, the config is empty.

This is what I get when I log config:

import Config from "react-native-config";
console.log(Config);

Output: {"dependencies": {}}

I have tried downgrading to version 1.4 and 1.3, but that does not help.

I have set this in the pre-actions without success:

cp "${PROJECT_DIR}/../.env.staging" "${PROJECT_DIR}/../.env"
echo “.env.staging” > /tmp/envfile
touch "${PROJECT_DIR}/../node_modules/react-native-config/ios/ReactNativeConfig/BuildDotenvConfig.rb"

Note that it worked fine on RN 0.70.9. Any help would be appreciated.

Update: I am having the exact same issue on Android

cal-overflow commented 1 year ago

Facing the same issue with RN 0.72.5. Though the console.log(Config) results in{}`.

kulak91 commented 1 year ago

Anticipating you are using expo. Launch it with EXPO_NO_DOTENV=1

gimi-anders commented 1 year ago

Anticipating you are using expo. Launch it with EXPO_NO_DOTENV=1

@kulak91 No, I am not using expo.

zabojad commented 1 year ago

I'm having the same issue with RN 0.72.5 (new arch not enabled). Has anyone found some solution or workaround ?

RamanSB commented 1 year ago

Same issue I'm running it with Expo & @kulak91 suggestion did not work.

kiwioz commented 1 year ago

I upgrade to RN 0.71.13 and then upgraded react-native-config from 1.4.6 to 1.5.1 at this point iOS Config became empty.

Downgrade react-native-config back to 1.4.6 and it started working again, Config was being returned as expected.

vanenshi commented 1 year ago

the same problem is happening in the android

Sahil6458 commented 1 year ago

https://github.com/luggit/react-native-config/issues/541#issuecomment-1491388207

vanenshi commented 1 year ago

https://github.com/luggit/react-native-config/issues/541#issuecomment-1491388207 I simply give permission to node_modules of read/write/execute . sudo chmod -R 777 node_modules/*

This hack gives us the idea that probably one of the files in the library doesn't have the correct permission. and seems like this is going to be related to Mac/Unix. @Sahil6458 but giving access to all the files in the node_modules is not a good idea, first of all we cannot force all our team members to use this method, and second, this is extremely dangerous I'll try to check which file lacks the permission and publish a patch

vanenshi commented 1 year ago

@gimi-anders can you please tell us your OS and xcode version?

gimi-anders commented 1 year ago

@vanenshi When I tried this the last time I was on OS 13 and xcode 14. I have now upgraded my OS and xcode, but I have not checked if that changes anything.

vanenshi commented 1 year ago

@gimi-anders i am using the xcode 15 and the same problem is happening, so its not related to the xcode version

tuanduc2904 commented 1 year ago

the same problem is happening in the android. NativeModules.ReactNativeConfigModule it's null

DonBrowny commented 1 year ago

I having the same in my app. Xcode Version: 15 react-native: 0.72.5

jeremy303 commented 1 year ago

+1 Xcode 14.3.1 react-native 0.72.5 react-native-config 1.5.1

Like @kiwioz, downgrading to 1.4.6 restored function.

esenbi commented 1 year ago

had same problem, turns out i missed this step in config https://github.com/luggit/react-native-config#app-extensions

waseemawan commented 1 year ago

Struggling with same issue from past two weeks, my error is in iOS build with error message "ReactNativeConfig.h" not found. Anyone got a real solution? Xcode 15 react-native 0.72.5 react-native-config 1.5.1 where the internal library name has changed to RNCConfig.h, (also tried 1.4.12 with old header file name ReactNativeConfig.h)

DonBrowny commented 1 year ago

I having the same in my app. Xcode Version: 15 react-native: 0.72.5

This was an issue with the nx monorepo. After updating nx version the issue got resolved.

gimi-anders commented 1 year ago

@vanenshi Any progress on this?

vanenshi commented 1 year ago

@vanenshi Any progress on this?

@gimi-anders sorry I caught up in some business related stuff and couldn't work on this. 🫠 My workaround was to detect the build type ("betaRelease" for example) and load the corresponding env manually (as a json file) Since our app don't need any native .env configuration, this solution was enough. 👌 Unfortunately, I won't be able to work on this issue. 🥲

gimi-anders commented 11 months ago

Has anyone got this library working on RN 0.71 or 0.72?

DonBrowny commented 11 months ago

Has anyone got this library working on RN 0.71 or 0.72?

Yes, i Have. I suspect the .env file location might be the issue for you. After the RN i need to change my ENVFILES location in the podfile

PS: I am using NX monorepo so my location of .env might look different from yours.

  ENVFILES = {
    'Debug' => '$(PODS_ROOT)/../../.env',
    'Release' => '$(PODS_ROOT)/../../.env',
  }
gimi-anders commented 11 months ago

Has anyone got this library working on RN 0.71 or 0.72?

Yes, i Have. I suspect the .env file location might be the issue for you. After the RN i need to change my ENVFILES location in the podfile

PS: I am using NX monorepo so my location of .env might look different from yours.

  ENVFILES = {
    'Debug' => '$(PODS_ROOT)/../../.env',
    'Release' => '$(PODS_ROOT)/../../.env',
  }

I will test this, but unfortunately this is not the complete solution, since I experience the same issue on both iOS and Android. Your suggestion only applies to iOS.

gimi-anders commented 11 months ago

Ok folks, it seems like this was completely an issue due to a silly mistake on my side. I will post it here, maybe someone has done the same mistake.

I had named the react-native config file incorrectly to react-native-config.js. After giving it the correct name react-native.config.js, the config works fine on both iOS and Android.

Case closed.

PortugalNeto commented 9 months ago

Ok folks, it seems like this was completely an issue due to a silly mistake on my side. I will post it here, maybe someone has done the same mistake.

I had named the react-native config file incorrectly to react-native-config.js. After giving it the correct name react-native.config.js, the config works fine on both iOS and Android.

Case closed.

But why have you closed this issue if a bunch of people is facing the same problem? In my case it's on both, iOS and android.

luizeduul commented 9 months ago

The same here

Roasted-Peanut commented 9 months ago

i had the same problem, can someone help me. https://github.com/lugg/react-native-config/issues/792

maharjanrajans commented 9 months ago

This worked for me! https://github.com/lugg/react-native-config/issues/770#issuecomment-1672621798 ensure that you add your BuildConfig to your proguard rules. Took me hours to figure out. IMHO the README needs a major makeover. This should be pretty much on top it.

In your proguard-rules.pro add

-keep class my.app.package.BuildConfig { *; }

Note Obviously you need to adapt the package to your actual app package name (my.app.package)

Roasted-Peanut commented 8 months ago
Screenshot 2024-03-08 at 17 47 32

Điều này đã hiệu quả với tôi! #770 (nhận xét) đảm bảo rằng bạn thêm BuildConfig vào quy tắc bảo vệ của mình. Tôi đã mất hàng giờ để tìm ra. IMHO README cần một sự thay đổi lớn. Điều này sẽ được khá nhiều trên đầu nó.

Trong proguard-rules.pro của bạn thêm

-keep class my.app.package.BuildConfig { *; }

Lưu ý Rõ ràng là bạn cần điều chỉnh gói phù hợp với tên gói ứng dụng thực tế của mình ( my.app.package )

it not work for me. Please help me! "react-native": "0.73.2", "react-native-config": "^1.5.1",

hieulamblackbird commented 8 months ago

work perfect on Xcode version 15.3 react-native-config , version 1.5.1 react-native , version 0.73.6

rithikronald commented 5 months ago

If the config is returning undefined in IOS try this, it worked for me "react-native": "^0.71.0", "react-native-config": "1.4.6",

For IOS: Add this line to the top of the pod file pod 'react-native-config', :path => '../node_modules/react-native-config'

vuquangit commented 4 months ago

If the config is returning undefined in IOS try this, it worked for me "react-native": "^0.71.0", "react-native-config": "1.4.6",

For IOS: Add this line to the top of the pod file pod 'react-native-config', :path => '../node_modules/react-native-config'

Thanks