expo / expo-cli

Tools for creating, running, and deploying universal Expo and React Native apps

Home Page:https://docs.expo.io/workflow/expo-cli/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

EAS Update not detecting .env files for different environments

onkardeol opened this issue · comments

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

commented

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.

@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).

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!

@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

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