Closed Menardi closed 3 years ago
hey, thanks for the report and investigation
the fix makes sense to me, looking forward to see the PR!
thanks!
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
Describe the bug
Native apps always use the variables from
index.web.js
, rather than the native variables, even ifjs_override
is not set.Steps to Reproduce
.env.development
withAPP_NAME=Development
and.env.production
withAPP_NAME=Production
<Text>
componentyarn rnuc .env.development && yarn android
Development
yarn rnuc .env.production
Production
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
rnuc
CLI to inject environment (default integration option from quickstart guide)react-native-ultimate-config
within monorepo managed with Lerna or Yarn Workspaces Monorepo supportEnv file
Example of env file that is causing problems
OS
Packages
react-native
: ❗ 0.65.1react-native-ultimate-config
: ❗3.4.1Additional context
Metro, the React Native bundler, prefers
browser
tomain
entries inpackage.json
, meaning that a native app will always take react-native-ultimate-config'sindex.web.js
file. However, it supports areact-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
: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 abrowser
orreact-native
entry in thepackage.json
. I presume it would choosebrowser
, but I don't know for sure.