Build losing process.env variable

Workflow: Managed
eas-cli version and node version: eas-cli/3.8.1 darwin-arm64 node-v18.12.1

I am trying to use process.env variable to dynamically build to different env, but I am running into an issue where the process.env in the app.config.json is losing it’s value. I just recently upgraded from sdk 45 to sdk 47. I consoled log in the app.config.json and I get the right value 2 and the undefined.

Here is the relevant code:
app.config.json

{
    ...config, \\ this is my config from my app.json file
    extra: {
      REACT_APP_STAGE: process.env.REACT_APP_STAGE,
    },
    runtimeVersion: {
      policy: 'sdkVersion'
    }
  };

eas build

{
  "cli": {
    "version": ">= 2.8.0"
  },
  "build": {
    // branch name
    "development": {
      "extends": "production",
      "developmentClient": true,
      "distribution": "internal",
      "channel": "development", // update your doing to the branch
      "autoIncrement": false,
      "env": {
        "REACT_APP_STAGE": "development"
      }
    },
    // branch name
    "staging": {
      "extends": "production",
      "autoIncrement": false,
      "channel": "staging", // update your doing to the branch
      "env": {
        "REACT_APP_STAGE": "staging"
      }
    },
    // branch name
    "production": {
      "distribution": "store",
      "channel": "production", // update your doing to the branch
      "autoIncrement": true, // will auto increment the buildNumber for ios and the versionCode for google
      "env": {
        "REACT_APP_STAGE": "production"
      },
      "ios": { "resourceClass": "m-medium" }
    }
  }
}

The config file that looks for what profile to set

return useProduction
  ? Config.getProdConfig()
  : useStaging
 ? Config.getStageConfig()
 : Config.getLocalConfig();

useProduction and useStaging

export const useProduction =
 Constants?.expoConfig?.extra?.REACT_APP_STAGE === 'production' ||
 Updates.channel === 'production';

export const useStaging =
 Constants?.expoConfig?.extra?.REACT_APP_STAGE === 'staging' ||
 Updates.channel === 'staging';

When console logging during build I get this
Screenshot 2023-03-20 at 3.18.48 PM

Any help would be appreciated.

Are you losing the variable in the build on EAS itself, or just when you run locally? You should be able to see it in the Spin Up Build Environment step of your build logs.

I did see that and I think I got that part working.

I do have another question about the build/update process and how long updates stay with the builds.

I have a build that went out yesterday using profile staging and was deployed to testflight, I then pushed some updates, and now that build is linked with a channel. All that works fine. My question is, If I do another build, with the same profile, it will not have the branch associated with it so there will be no updates correct?

This depends on your runtime version policy. A build checks for updates based on platform, runtime version, and channel. If those stay the same between builds, each build would download the update.

Thanks for the clarification!

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.