EAS update未加载指定环境变量的问题求助
问题原因及解决方案
核心原因
执行eas update时未指定对应profile,EAS默认会使用development配置的环境变量,而eas.json中定义的profile环境变量优先级高于通过dotenv加载的.env.preview变量,导致后者被覆盖。
解决方案
方案1:执行update时指定preview profile
直接在命令中指定使用preview配置,确保EAS读取对应环境的变量:
dotenv -e .env.preview -- eas update --profile preview
方案2:调整eas.json配置,让update复用build的profile
在eas.json中新增update字段,让各环境的update配置复用对应build的环境变量,避免重复定义:
{ "cli": {"version": ">= 5.9.0"}, "build": { "development": { "channel": "development", "developmentClient": true, "distribution": "internal", "ios": {"simulator": true}, "env": { "EXPO_PUBLIC_API_URL": "http://123.45.678.90:8700/api", "NODE_ENV": "development" } }, "preview": { "channel": "preview", "distribution": "internal", "env": { "EXPO_PUBLIC_API_URL": "https://example.com/api", "NODE_ENV": "production" } }, "production": { "channel": "production", "extends": "preview", "distribution": "internal" } }, "update": { "development": { "channel": "development", "env": {"extends": "build.development.env"} }, "preview": { "channel": "preview", "env": {"extends": "build.preview.env"} }, "production": { "channel": "production", "env": {"extends": "build.production.env"} } }, "submit": {"production": {}} }
之后执行命令时指定profile即可:
eas update --profile preview
(若需结合dotenv,仍可保留dotenv -e .env.preview --前缀,但eas.json中的env优先级更高)
补充说明
EAS环境变量优先级从高到低为:
eas.json对应profile的env字段- 系统环境变量(含
dotenv加载的变量) .env文件中的变量
内容的提问来源于stack exchange,提问作者Mike K
相关产品推荐
相关产品推荐

