4

I have dynamic configuration for my EAS environment:

eas.json

{
  "cli": {
    "version": ">= 0.55.1",
    "appVersionSource": "local"
  },
  "build": {
    "development": {
      "distribution": "internal",
      "ios": {
        "simulator": true
      },
      "env": {
        "API_URL": "http://localhost/",
        "APP_ENV": "development",
      }
    },
    "staging": {
      "distribution": "internal",
      "env": {
        "API_URL": "https://dev.my-url.com/",
        "APP_ENV": "staging",
   
      }
    },
    "production": {
      "env": {
        "API_URL": "https://my-url.com/",
        "APP_ENV": "production",
      }
    }
  },
  "submit": {
    "production": {
      "android": {
        "serviceAccountKeyPath": "./keys/pc-api-ccc.json",
        "track": "internal"
      }
    },
    "staging": {
      "extends": "production"
    }
  }
}

and accordingly have app.config.js

import "dotenv/config";

export default () => {
  console.log("ENV", process.env.API_URL);

  return {
    
    //...

    extra: {
      API_URL: process.env.API_URL,
      APP_ENV: process.env.APP_ENV,
      DEEP_LINK: process.env.DEEP_LINK,
      eas: {
        projectId: "2c680410-428f-431d-911f-fb378e45b885",
      },
    
    //...
};

For some reason, after running eas build -p ios --profile staging config default function is called 3 times and in last call environment variables are lost:

console.log output:

ENV https://my-url.com/
ENV https://my-url.com/
ENV undefined

Any idea why 3 times? or why I'm loosing env variables on last call?

Lasharela
  • 1,307
  • 1
  • 11
  • 23
  • im guessing that you have run expo prebuild, right? (you have android and iOS folders?) – Eduardo Palacio Oct 08 '22 at 05:17
  • No, I'm running `eas build -p ios --profile staging` but I do have both. For android it's show 2 times. first time I'm getting env vars, second time it's undefined. – Lasharela Oct 09 '22 at 00:45
  • 1
    that may be the reason, before running `eas build` run `expo prebuild --npm --clean` this will recreate your iOS and android folders, was build what do is compress your code and check if you have those folders and upload it to build them. – Eduardo Palacio Oct 09 '22 at 01:06
  • https://github.com/babel/minify/tree/master/packages/babel-plugin-transform-inline-environment-variables – Raul Jan 12 '23 at 23:27
  • Hi, if i set my env varaibles inside app.config.js do i also need to set this inside my eas.json? – kd12345 Jan 15 '23 at 08:11
  • yes, if you want to change it while build at EAS – Lasharela Feb 09 '23 at 05:13

0 Answers0