◉RORK LABJP
●SUBDOMAIN — Rork can now connect your web app to a subdomain only, leaving your root domain and www untouched (12/1)●UPDATES — expo-updates 58.0.23 fixes Android release builds embedding a stale runtime version●FLASH END — Intro pricing for Gemini Flash models ends 12/31, 29 days from now. Time to recheck AI feature costs●HMR — Some report the dev server picking up another server's bundle and then exiting●FIRST VIEW — Map the first screen for a normal launch, a notification, and a link, and back navigation stops surprising you●CARBON — Gemini 4 Carbon and Argon are now at standard rates: $4.00 input, $20.00 output per 1M tokens●SUBDOMAIN — Rork can now connect your web app to a subdomain only, leaving your root domain and www untouched (12/1)●UPDATES — expo-updates 58.0.23 fixes Android release builds embedding a stale runtime version●FLASH END — Intro pricing for Gemini Flash models ends 12/31, 29 days from now. Time to recheck AI feature costs●HMR — Some report the dev server picking up another server's bundle and then exiting●FIRST VIEW — Map the first screen for a normal launch, a notification, and a link, and back navigation stops surprising you●CARBON — Gemini 4 Carbon and Argon are now at standard rates: $4.00 input, $20.00 output per 1M tokens
Articles/Dev Tools
⬡ Dev Tools/2026-10-15Beginner

When EXPO_PUBLIC_ Values Read Fine in Dev but Come Back undefined in Production: Telling the Spellings Apart

The API URL reads fine while developing and turns undefined once the app is built. The cause was how process.env was written, and how the value reaches the build. babel-preset-expo's output for dev and production side by side, a table for causes outside the code, an env.ts that stops at startup, and a way to check the bundle itself.

Expo240Environment Variables4EXPO_PUBLIC4Rork622Troubleshooting55

Sometimes a screen that worked all through development stops fetching data the moment you install a real build on a device. No error message appears. The screen is just empty.

The first thing I check is whether the API URL came through empty. As an indie developer I often switch a server address through an environment variable, and when the address ships as undefined, the symptom looks like it simply disappeared.

What I most want to say up front: a value that reads fine on the dev server is no evidence that it will read in production. I put the transformed output side by side to see why.

What I checked, and how far

I checked two things: the Babel transform Expo uses, and the single line the dev server injects. Versions were babel-preset-expo 57.0.15, @expo/metro-config 57.0.13, and Node 22.

I did not bundle with Metro or run on Hermes. I transformed the source and then executed the result with process.env holding only NODE_ENV. Whether a device behaves the same is something to confirm in your own project, using the last step below.

What this showed is that dev and production get their environment variables in two entirely different ways.

  • Production build: anywhere that reads process.env.EXPO_PUBLIC_NAME is replaced at build time by the string itself. Anywhere that wasn't replaced is left with nothing.
  • Dev server: separately from that replacement, one line is placed at the top of the bundle that copies every EXPO_PUBLIC_ variable into process.env.

So in dev, even a spelling that never gets replaced can still read process.env directly and find the value.

Result per spelling

I passed the same value, https://api.example.com, and ran each spelling in dev and in production.

Spelling Dev Production
process.env.EXPO_PUBLIC_API_URLreadsreads
const { EXPO_PUBLIC_API_URL } = process.envreadsreads
process.env["EXPO_PUBLIC_API_URL"]readsreads
process.env[key] (key is a variable)readsundefined
const env = process.env; env.EXPO_PUBLIC_API_URLreadsundefined
read(process.env) (passing the whole object)readsundefined
process.env.API_URL (no prefix)undefinedundefined

The three bold rows are the spellings that work in dev and break only in production. What they share is that the name is not finished inside a single expression. The replacement only fires when process.env and the name sit in the same expression. Once a variable is in between, the name isn't known at the point of writing, and the spelling falls outside the replacement.

One thing surprised me. The official documentation reads as if destructuring and bracket spellings are not replaced. In this version, destructuring and a string-literal bracket were replaced. I couldn't tell whether the documentation is out of date or whether it depends on settings and versions.

Which spellings pass may shift between versions, so I stay with the direct form instead of leaning on them. That sentence is my line for now.

When the spelling is right and production is still empty

If fixing the spelling doesn't bring the value back, the next suspect is that the value never reached the machine doing the build. I once reread my code three times before realizing the .env file simply didn't exist where the build ran. The symptom is identical; the cause is often outside the code.

Symptom Likely cause How to check Fix
Fine in local dev, empty only in the EAS Build artifact.env is in .gitignore, so it never reaches the EAS build machineLook in the build log for the step that loads environment variables and see whether the name appearsRegister the value as an EAS environment variable (production, etc.) and point the eas.json profile at that environment
You changed the value locally and still see the old oneMetro is serving a cached transformStop the dev server, start it again, and compareRestart with npx expo start --clear
Only a local Android release build still points at the old serverGradle skipped the bundle task as UP-TO-DATEFind the bundle task's line in the build outputForce the bundle to rebuild, as described in the article linked below
The store build is right, but an OTA update ships emptyThe machine that ran eas update didn't have the valueRecall where and how the update was createdLoad the same environment's values when creating updates as when building
undefined everywhereThe name lacks the EXPO_PUBLIC_ prefix, or is misspelledPut the names in .env and in the code side by sideAdd the prefix and define each name in one place

The first row is a path Expo's own EAS FAQ describes (as of December 2026). A .env file that isn't committed to Git doesn't reach a cloud build. The dev server can read it only because it's reading the file on your disk.

The Android case in the third row looks so similar that it's easy to mix up, so I handled it separately in I rebuilt Android with a new environment variable and the app still points at the old server.

Finding the risky lines in your own code

What you're looking for is any line where process.env isn't immediately followed by .name.

# Print only lines where process.env is not followed by "."
grep -rnE "process\.env(\[|[^.A-Za-z_\[]|$)" src \
  --include="*.ts" --include="*.tsx" --include="*.js" --include="*.jsx"

Run against a small test file of about seven lines, it printed exactly three: the variable key, the alias, and the pass-the-object case. A string-literal bracket is safe yet still matches, so treat the output as a list to read line by line.

Gather the reads in one place, and stop at startup if empty

The fix is to read in one place, write only that place in the direct form, and stop before an empty screen appears.

// src/env.ts
// Read each value as "process.env.NAME" directly. This is what gets replaced at build time.
const raw = {
  EXPO_PUBLIC_API_URL: process.env.EXPO_PUBLIC_API_URL,
  EXPO_PUBLIC_SENTRY_DSN: process.env.EXPO_PUBLIC_SENTRY_DSN,
} as const;
 
const missing = Object.entries(raw)
  .filter(([, value]) => !value)
  .map(([name]) => name);
 
if (missing.length > 0) {
  throw new Error(`Public env vars are empty: ${missing.join(', ')}`);
}
 
export const env = raw as Record<keyof typeof raw, string>;

Everywhere else, import { env } from "./env" and use env.EXPO_PUBLIC_API_URL.

I transformed this with the production settings and ran it. With both values present it passed; with one removed it stopped with a message naming EXPO_PUBLIC_SENTRY_DSN. Because it stops right at startup, there is less time spent searching for the cause while staring at an empty screen. The point is to learn, before your users do, that the production build never received the value.

If throwing feels too blunt, you could throw only in development builds and show a "couldn't load settings" message in production. I still throw in production. An app that keeps running with an empty value tends to collect a one-line review saying "nothing shows up," and leaves me with no clue to follow.

Three common misunderstandings

"With the EXPO_PUBLIC_ prefix, any spelling works." The prefix only decides which names are eligible for replacement. Expo's environment variables guide explains that values are inlined when referenced statically as process.env.NAME. With the prefix but a variable key or an alias in between, production still loses the value, as the table above shows.

"EXPO_PUBLIC_ values can be swapped on the server after the build." They are written into the bundle as plain strings at build time. To change one, you build again or publish a new OTA update. Settings you want to change at runtime belong in something the app fetches on launch, not in environment variables.

"Marking a variable as secret in EAS keeps it out of the app." Visibility controls who can read the value in the dashboard. A value with the EXPO_PUBLIC_ prefix still ends up in the bundle. I go through those two axes in the article linked at the end.

The next place it tends to break: OTA updates

Once the store build is fixed, the next report I usually hear is "the version I shipped with EAS Update is empty again." An OTA update bundles whatever values exist where the update is created. Your build may read EAS environment variables, but if you create the update from your own terminal and the value isn't there, the update ships empty.

Before creating an update, I run the src/env.ts check locally once. The throw above fires there too, so I find out before shipping an empty version.

One last check on a real build

My reproduction stops at the transform, so it's worth looking at a real bundle too. You can search the build output for the value as a string.

# Export a production bundle and count files that contain the API URL
npx expo export --platform ios
grep -rl "https://api.example.com" dist | head

Replace api.example.com with your own address. If nothing turns up, the replacement did not happen. This check assumes the value is meant to be in the bundle. Secrets that must not be there should never carry the EXPO_PUBLIC_ prefix at all, which I wrote up in EAS secrets are not a "keep it out of the app" setting.

What I checked, and what I didn't

The transform results come from babel-preset-expo 57.0.15 and Node 22, as of October 2026. I did not confirm the behavior on Hermes on a device, the exact wording in EAS Build logs, or the names of every eas update option. Option names can change between versions, so check eas update --help for yours.

To start, run the grep above once on your own project today and see how many lines it prints. If it's zero and production is still empty, work down the table of causes outside the code from the top.

Share

Thank You for Reading

Rork Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • ✦Copy-paste ready implementation code
  • ✦New advanced guides published daily
  • ✦$5/mo or $10 for lifetime access
View Membership →

If you found this article helpful, a small tip ($1.50) would mean a lot to us. Your support helps keep this site ad-free and covers server and hosting costs.

Related Articles

⬡ Dev Tools2026-10-13
Before You Ship: Go Looking for Your Own Keys Inside the Exported Expo Bundle
A key can be missing from your source and still be sitting inside the finished app. I ran expo export on Expo SDK 57, searched the bundle with grep and a short Node script, and recorded which secrets show up and which don't.
⬡ Dev Tools2026-10-30
It runs in development but the iOS Release build dies on launch — checking whether a missing scheme is the cause
In an expo-router app, an app.json with no scheme can crash only the iOS Release build at launch. A triage table for Release-only crashes, how to read the reason from the log, why Debug and Android survive, the two fixes and why one needs a native rebuild, and a pre-submission check.
⬡ Dev Tools2026-09-21
A build that stops with exit code 0 — the flag that silenced the log, and the check that let an empty file through
Two reports landed in the same week: eas build --local stopping with exit code 0 but produced no further output, and a zero-byte stub that never got embedded. Both came down to settings that reduce output. Here is how to audit your own scripts.