-
Notifications
You must be signed in to change notification settings - Fork 477
Cannot use env data in dynamic configuration #2782
Comments
watching this issue, it stopped working suddenly |
anyone could point me on how to restore @expo/xdl@58.0.3 or less in order to have the possibility of reading the configuration dynamically? |
I'd imagine the issue is related to the more stringent rules used in the babel transform:
This recent change seems related to the PR you originally proposed 0464f6c |
hi there! i discussed this with @EvanBacon, here's a summary: why babel-plugin-dotenv-import isn't working with app.config.js anymorewe stopped using the project's babel config for transpiling the app config because the environment that your app code runs in is dramatically different from the environment that the app config code runs in, and also many of the transforms that you need for your app may not be needed for your app config. it's easy to get into a state where some babel plugin you use in your react app in javascript core on an ios and android device will produce code that does not run in the expo-cli environment in node. so we use alternatives you can use now
possible future solutions
if anyone wants to take a shot at one of these solutions (i prefer the envName option) it would be appreciated. if you have other ideas, let us know! |
thank you @brentvatne Correct me if I'm wrong, I should use direnv for the appconfig, and a different approach (e.g. dotenv) for runtime logic? Because direnv does't seem to work when I try to load a dinamic tab bar in environment.ts export const mainNavigator = () =>require(
also, would this method require special care when building in order for the variables to be hooked? |
Hi everyone |
correct @superandrew! something like babel-plugin-inline-dotenv will inline your env vars at build time, which is the only sensible thing to do with them on the front end because there is no process.env environment that you control in that context (the user's device). with respect to this:
i'm not familiar what technique you would use to make this work. in metro your imports need to all be static, it's not like node where you can define the import string at runtime. perhaps you can get this working with babel but i have never explored this so i can't comment. @marcor-ts - you can refer to #2786 - notice that you can control the options that are passed in to babel there. you'd need to check if there is some config file with the specific name we choose to use (above i said |
This issue is stale because it has been open for 60 days with no activity. If there is no activity in the next 7 days, the issue will be closed. |
We don't plan on exposing a custom babel config for the |
Hello,
I am a maintainer of React Native Tools VS Code extension. The extension is used for debugging React Native (including Expo) applications.
Description
We received an issue with usage of
env
variables in dynamic configuration. Then we tried to reproduce it on a plain Expo project running it from the terminal and we also got an error. In the project we use the babel-plugin-dotenv-import package to access env variables.We have already faced a similar problem before and proposed a fix for it in this PR.
Expected Behavior
It would be great to have an opportunity to use env variables in dynamic configuration as it worked earlier.
Observed Behavior
When we start a project from the terminal using the
expo start
, we get the following error:We found out that this problem arose since
@expo/xdl@58.0.4
package after the cf63ad0 commit. We consider that the problem could be in the config file compilation here. We think so, because according to the original error it cannot use@env
module:But it used to work properly when a separate process with
@babel/register
was used.Environment
Expo SDK version: 39
Reproducible Demo
Create a plain Expo project
Add the babel-plugin-dotenv-import package to the project and do all the preparation written in the Usage guide
Add
app.config.ts
file to the project as written here. Here is our config file:Create a
.env
file, e.g.:Start the project using the
expo start
commandThe text was updated successfully, but these errors were encountered: