maxkomarychev / react-native-ultimate-config

Config that works
MIT License
262 stars 31 forks source link

Native apps are using web configuration #76

Closed Menardi closed 3 years ago

Menardi commented 3 years ago

Describe the bug

Native apps always use the variables from index.web.js, rather than the native variables, even if js_override is not set.

Steps to Reproduce

Editing the config in node_modules/react-native-ultimate-config/index.web.js will also cause the text to change, showing that the native app is taking the value from here, instead of from the native configuration.

Expected behavior

The environment variables should only change when a new native build is done.

Environment

Integration option

Env file

Example of env file that is causing problems

APP_NAME=Development

OS

Packages

Additional context

Metro, the React Native bundler, prefers browser to main entries in package.json, meaning that a native app will always take react-native-ultimate-config's index.web.js file. However, it supports a react-native key, which takes priority over both of these (see https://github.com/facebook/metro/blob/7e99d9eb673469f88d0c03544f4533b4f56f75f9/packages/metro/src/ModuleGraph/node-haste/Package.js#L108-L116 for the implementation of that).

I think the fix should be quite simple, just adding one line to the package.json:

"react-native": "index.js",

I will create a PR for this, but I have never used react-native-web before, so I don't know if its bundler will prefer a browser or react-native entry in the package.json. I presume it would choose browser, but I don't know for sure.

maxkomarychev commented 3 years ago

hey, thanks for the report and investigation

the fix makes sense to me, looking forward to see the PR!

thanks!

Menardi commented 3 years ago

The PR is at https://github.com/maxkomarychev/react-native-ultimate-config/pull/77, and I have tested that web still works with the change, thanks to some detailed instructions from @elliotdickison