Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

EAS Update not detecting .env files for different environments #4765

Closed
onkardeol opened this issue Oct 2, 2023 · 5 comments
Closed

EAS Update not detecting .env files for different environments #4765

onkardeol opened this issue Oct 2, 2023 · 5 comments
Labels
needs review Issue is ready to be reviewed by a maintainer

Comments

@onkardeol
Copy link

Summary

I am attempting to setup my app to utilize EXPO_PUBLIC environment variables with EAS Update.
https://docs.expo.dev/eas-update/environment-variables/

My eas.json:

{
  "build": {
    "base": {
      "node": "18.18.0",
      "yarn": "1.22.19",
      "android": {
        "image": "default",
        "env": {
          "PLATFORM": "android"
        }
      },
      "ios": {
        "image": "latest",
        "env": {
          "PLATFORM": "ios"
        }
      }
    },
    "development": {
      "extends": "base",
      "developmentClient": true,
      "android": {
        "distribution": "internal",
        "withoutCredentials": true
      },
      "ios": {
        "simulator": true
      }
    },
    "staging": {
      "channel": "staging",
      "extends": "base",
      "distribution": "internal",
      "android": { "buildType": "apk" },
      "ios": { "simulator": false }
    },
    "production": {
      "channel": "production",
      "extends": "base"
    }
  }
}

I have 3 environment files:

  1. .env.development
  2. .env.staging
  3. .env.production

Each of these env files contains 1 environment variable EXPO_PUBLIC_API_URL which is the url of my api.

The Problem

When i run the app locally using yarn expo start
My console outputs

env: load .env.development
env: export EXPO_PUBLIC_API_URL

which is correct.

HOWEVER, when I run eas update --channel staging
My console outputs

✔ Provide an update message: … stable [expo-cli] 
env: load .env.production [expo-cli] 
env: export EXPO_PUBLIC_API_URL

I have tried messing around with the config files. I've scoured the docs multiple times with no results. I am expecting eas to use the .env.staging config when i run eas update --channel staging

Environment

  expo-env-info 1.0.5 environment info:
    System:
      OS: macOS 13.4
      Shell: 3.2.57 - /bin/sh
    Binaries:
      Node: 18.18.0 - /usr/local/bin/node
      Yarn: 1.22.19 - /usr/local/bin/yarn
      npm: 9.8.1 - /usr/local/bin/npm
    SDKs:
      iOS SDK:
        Platforms: DriverKit 22.4, iOS 16.4, macOS 13.3, tvOS 16.4, watchOS 9.4
    IDEs:
      Xcode: 14.3/14E222b - /usr/bin/xcodebuild
    npmPackages:
      @expo/webpack-config: ^19.0.0 => 19.0.0 
      expo: ^49.0.0 => 49.0.11 
      react: 18.2.0 => 18.2.0 
      react-dom: 18.2.0 => 18.2.0 
      react-native: 0.72.4 => 0.72.4 
      react-native-web: ~0.19.6 => 0.19.9 
    npmGlobalPackages:
      eas-cli: 5.2.0
    Expo Workflow: bare

Please specify your device/emulator/simulator platform, model and version

iPhone 13 Pro Max

Error output

No response

Reproducible demo or steps to reproduce from a blank project

Starting a project with the above-mentioned .env setup and eas.json setup should reproduce the issue

@onkardeol onkardeol added the needs review Issue is ready to be reviewed by a maintainer label Oct 2, 2023
@akinwol
Copy link

akinwol commented Oct 12, 2023

I am also struggling with this issue. Eas build uses eas.json to create the env variables but for eas updates I can't seem to get it to use env.staging or env.development. It just defaults to whats in env.production.

@ghost
Copy link

ghost commented Oct 25, 2023

@onkardeol Have you tried adding NODE_ENV=development before the eas update command? It may not be the nicest solution, but it seems to work for me (only locally, though).

@byCedric
Copy link
Member

Hi all! The eas.json build profile does not relate to the "standard dotenv" environments. Dotenv is based on NODE_ENV, and autoselects the right .env.* files based on dotenv-rails conventions. The eas.json build profile names do not overlap with this concept.

In eas.json, you can define a set of environment variables you want for that specific build through the env property. If these environment variables contain semi-secret strings, I would recommend using EAS Secrets.

⚠️ Keep in mind that if you use the secret in your app, it's always compiled into the binary. Do not use secret credentials or tokens directly in your app, use an API in between instead.

We still need a better story about how these two mechanisms relate; feel free to open suggestions on our docs at github.com/expo/expo if you have a good idea.

For now I'll close this issue as this repository will be archived soon. Hope this helps!

@matart15
Copy link

matart15 commented Jan 7, 2024

@byCedric Looks like secrets are not loading when i use pnpx eas-cli update --branch preview --message \"update try\"

I have secrets set.
Screenshot 2024-01-07 at 14 58 06
image

then on preview i tried

<Pressable
              onPress={() => {
                Alert.alert("", JSON.stringify(process.env));
              }}
            >

This is all there is

Screenshot 2024-01-07 at 15 02 03

@matart15
Copy link

matart15 commented Jan 7, 2024

Oh. I did not see issue wa closed. opening new one
expo/eas-cli#2170

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs review Issue is ready to be reviewed by a maintainer
Projects
None yet
Development

No branches or pull requests

4 participants