Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eas update appears to be changing an environment variable in my build #2236

Open
HM-23-HM opened this issue Feb 19, 2024 · 13 comments
Open

eas update appears to be changing an environment variable in my build #2236

HM-23-HM opened this issue Feb 19, 2024 · 13 comments
Labels
needs review Issue is ready to be reviewed by a maintainer

Comments

@HM-23-HM
Copy link

HM-23-HM commented Feb 19, 2024

Build/Submit details page URL

https://expo.dev/accounts/hodeem/projects/sheltah/builds/7eb6fb53-0f9a-4ba0-b00d-cba0834d947d

Summary

I have SERVER set in both the local .env file and the eas.json file. The .env file is in the .gitignore file.
In the JS code, the SERVER value is referenced by using const SERVER = process.env.SERVER.

If I run eas build with a profile, platform etc., the JS code uses the correct SERVER value from selected build profile.

However, when I run eas update, the JS code intermittently uses the SERVER value that I only have in the local .env file.

I say "intermittently" because it appears that the change happens on the first eas update, but I can't change the SERVER value via. the .env file with any subsequent eas update. It has happened twice so far. Can someone let me know what I'm doing wrong or if this is a legitimate bug.

Managed or bare?

Managed

Environment

Output from npx expo-env-info:


  expo-env-info 1.2.0 environment info:
    System:
      OS: macOS 11.7.4
      Shell: 5.8 - /bin/zsh
    Binaries:
      Node: 18.18.1 - ~/.nvm/versions/node/v18.18.1/bin/node
      Yarn: 1.22.19 - ~/.nvm/versions/node/v18.18.1/bin/yarn
      npm: 9.8.1 - ~/.nvm/versions/node/v18.18.1/bin/npm
      Watchman: 2023.08.28.00 - /usr/local/bin/watchman
    Managers:
      CocoaPods: 1.15.2 - /usr/local/bin/pod
    SDKs:
      iOS SDK:
        Platforms: DriverKit 21.2, iOS 15.2, macOS 12.1, tvOS 15.2, watchOS 8.3
    IDEs:
      Android Studio: 2022.1 AI-221.6008.13.2211.9514443
      Xcode: 13.2.1/13C100 - /usr/bin/xcodebuild
    npmPackages:
      @expo/metro-config: ~0.10.0 => 0.10.7 
      babel-preset-expo: ^9.5.2 => 9.5.2 
      expo: ^48 => 48.0.20 
      react: 18.2.0 => 18.2.0 
      react-native: 0.71.14 => 0.71.14 
      react-native-web: ~0.18.10 => 0.18.12 
    npmGlobalPackages:
      eas-cli: 7.2.0
    Expo Workflow: managed
    ```
    
    Output from `npx expo-doctor`:

✔ Check Expo config for common issues
✔ Check package.json for common issues
✔ Check dependencies for packages that should not be installed directly
✔ Check for common project setup issues
✔ Check for issues with metro config
✔ Check npm/ yarn versions
✔ Check Expo config (app.json/ app.config.js) schema
✔ Check that packages match versions required by installed Expo SDK
✔ Check for legacy global CLI installed locally
✔ Check that native modules do not use incompatible support packages
✔ Check that native modules use compatible support package versions for installed Expo SDK

Didn't find any issues with the project!


### Error output

N/A

### Reproducible demo or steps to reproduce from a blank project

1. Run `eas build --auto-submit --profile production --platform android`
2. Run `eas submit --channel production`

Files:
.env

SERVER=https://local-domain.com


.gitignore

node_modules/
.expo/
npm-debug.*
*.jks
*.p8
*.p12
*.key
*.mobileprovision
.orig.
web-build/

macOS

.DS_Store

.env*

android/
ios/

@generated expo-cli sync-e7dcf75f4e856f7b6f3239b3f3a7dd614ee755a8

The following patterns were generated by expo-cli

OSX

.DS_Store

Xcode

build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
project.xcworkspace

Android/IntelliJ

build/
.idea
.gradle
local.properties
*.iml
*.hprof

node.js

node_modules/
npm-debug.log
yarn-error.log

BUCK

buck-out/
.buckd/
*.keystore
!debug.keystore

Bundle artifacts

*.jsbundle

CocoaPods

/ios/Pods/

Expo

.expo/
web-build/
dist/

@EnD expo-cli

dont_upload/

*/Spring Boot
**/build
*.keystore
*.apk

artifacts


eas.json

{
"cli": {
"version": ">= 3.8.1",
"appVersionSource": "remote"
},
"build": {
"internal": {
"developmentClient": true,
"distribution": "internal",
"ios": {
"simulator": true,
"resourceClass": "m-medium",
"cocoapods": "1.15.2"
},
"android": {
"developmentClient": true
},
"channel": "development"
},
"staging": {
"distribution": "store",
"ios": {
"resourceClass": "m-medium",
"cocoapods": "1.15.2",
"autoIncrement": "buildNumber"
},
"android": {
"resourceClass": "medium",
"buildType": "app-bundle",
"autoIncrement": "versionCode"
},
"channel": "staging",
"env": {
"SERVER": "https://staging-domain.com
}
},
"production": {
"extends": "staging",
"channel": "production",
"env":{
"SERVER": "https://production-domain.com"
}
}
},
"submit": {
"production": {
"android": {
"serviceAccountKeyPath": "./dont_upload/google-service-account-key.json",
"track": "production"
},
"ios": {
"appleId": "",
"ascAppId": "
",
"appleTeamId": "***"
}
},
"staging": {
"extends": "production",
"android": {
"track": "alpha"
}
}
}
}


app.config.js

module.exports = ({ config }) => ({
"expo": {
"name": "",
"scheme": "
",
"slug": "",
"version": "1.0.1",
"orientation": "portrait",
"icon": "./assets/house_icon.png",
"userInterfaceStyle": "automatic",
"splash": {
"image": "./assets/house_icon.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"assetBundlePatterns": [
"
/
"
],
"ios": {
"supportsTablet": true,
"bundleIdentifier": "",
"googleServicesFile": "./config/firebase/GoogleService-Info.plist",
},
"android": {
"package": "
",
"googleServicesFile": "./config/firebase/google-services.json",
"config": {
"googleMaps": {
"apiKey": ''
}
}
},
"web": {
"favicon": "./assets/favicon.png"
},
"extra": {
"eas": {
"projectId": "
"
},
},
"plugins": [
[
"expo-build-properties",
{
"ios": {
"useFrameworks": "static"
}
}
],
"@react-native-firebase/app",
"@react-native-firebase/crashlytics",
"@react-native-firebase/perf",
[
"expo-image-picker",
{
"cameraPermission": "You may need to take photos of your listing with the device camera.",
"photosPermission": "You may need to upload photos of your listing from the photo gallery.",
}
],
["expo-tracking-transparency", {
"userTrackingPermission": "This identifier will be used to deliver personalized ads to you."
}],
"./plugins/android_manifest",
"./plugins/main_activity"
],
"updates": {
"url": "***"
},
"runtimeVersion": {
"policy": "sdkVersion"
},
},
...config
})


app.json:

{
"react-native-google-mobile-ads": {
"android_app_id": "",
"ios_app_id": "
",
"user_tracking_usage_description": "This identifier will be used to deliver personalized ads to you.",
"sk_ad_network_items": [***],
}
}



@HM-23-HM HM-23-HM added the needs review Issue is ready to be reviewed by a maintainer label Feb 19, 2024
@leons1767
Copy link

eas update does not have access to SECRETS variables or environment variables that you defined in eas.json. You can use dotenv to export the .env variables locally to eas update. Obviously, you need to maintain the correct SERVER value in your .env.

@HM-23-HM
Copy link
Author

@leons1767 let's say that I am maintaining the correct SERVER value in the .env file, can you explain why eas update changes the value intermittently?

@HM-23-HM HM-23-HM closed this as not planned Won't fix, can't repro, duplicate, stale Feb 20, 2024
@leons1767
Copy link

leons1767 commented Feb 21, 2024

@leons1767 let's say that I am maintaining the correct SERVER value in the .env file, can you explain why eas update changes the value intermittently?

I don't think it changes the value intermittently, it just picks up whatever the SERVER value is when you run eas update. You can ensure the right environment variables by loading it from .env using dotenv prior to eas update.

@mkhoussid
Copy link

mkhoussid commented Mar 3, 2024

I deleted a previous comment, because I found the relevant documentation for this issue

@leons1767
Copy link

I deleted a previous comment, because I found the relevant documentation for this issue

Glad that you are able to find the answer from the documentation. Have a nice day!

@HM-23-HM HM-23-HM reopened this Mar 21, 2024
@MCervenka
Copy link

happen to me also, it was intermittenly, because it somehow cached the .env value.
so the update needs to be run with --clear-cache flag

@Damonio
Copy link

Damonio commented May 6, 2024

I was breaking my head because this too, I tough that the .env file picked was a wrong one but the problem was the cache, deleting the cache helped me too

    "publish:prod": "cross-env NODE_ENV=production eas update --clear-cache --channel prod --message \"Automated publish to prod\""

@abpbackup
Copy link

https://expo.dev/blog/what-are-environment-variables#synchronizing-between-environment-variables-in-eas-update-and-eas-build

As described here, it is NOT the cache as mentioned before. Is the way EAS UPDATE works that DO NOT use the eas.json env vars a EAS BUILD does.

@myeljoud
Copy link

happen to me also, it was intermittenly, because it somehow cached the .env value. so the update needs to be run with --clear-cache flag

Perfect! Thanks, I had the same problem and it is now resolved!

@yourjhay
Copy link

yourjhay commented Jul 26, 2024

happen to me also, it was intermittenly, because it somehow cached the .env value. so the update needs to be run with --clear-cache flag

This is exactly why.. when changing .env after update is publish .. it will use the previous value set in .env when doing another publish..

--clear-cache works !

@mayel15
Copy link

mayel15 commented Aug 16, 2024

NODE_ENV=production eas update --clear-cache

I faced to the same problem and the --clear-cache works for loading env var for eas update

@moritzlang
Copy link

Same happened to me. Ran eas update locally and it used a cached .env file, which broke production.
Very scary to use this command, therefore set up a github workflow to trigger it in an encapsulated environment.

@rafael-repasse
Copy link

The thing is, eas update does somehow cache .env variables. --clear-cache fixed it, but this shouldn't happen at all since it doesn't happen with eas run:android for example.

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

No branches or pull requests