The Night Cloudflare Ate My Environment Variables
There are horror stories about production bugs.
This is one of them.
It started innocently. A dashboard. A Firebase config. A Cloudflare Pages deployment.
Nothing exotic. Nothing clever. Code I’ve deployed before. Code that worked locally. Code that worked in another project.
And yet-
“Missing required Firebase configuration.”
The message appeared like a whisper from a dark hallway.
Act I: Everything Is Correct
The environment variables were there.
I checked.
Then checked again.
NEXT_PUBLIC_FIREBASE_API_KEY? Present.
PROJECT_ID? Present.
Everything spelled correctly. Everything in plaintext. Everything redeployed.
Still broken.
Local build? Perfect.
Cloudflare build? Screaming.
At this point, the code wasn’t suspicious.
The platform was.
Act II: The Gaslighting Begins
Cloudflare showed the variables.
The UI confirmed they existed.
The build logs pretended they didn’t.
I added logs. I removed logs. I redeployed.
Same result.
“Firebase config not available during build.”
A lie.
Or worse-something that used to be true.
Act III: Circling the Abyss
I changed nothing.
Then everything.
- Secrets → Plaintext
- Plaintext → Secrets
- Rebuild
- Redeploy
- Rebuild again
Still nothing.
At this point, the codebase was clean.
The rules were correct.
The indexes were created.
And yet, the app refused to acknowledge reality.
Act IV: The Ritual
Out of frustration, not logic, I did something irrational.
I deleted the environment variables.
One. By. One.
No bulk delete.
No replace.
Just deliberate removal.
Then I re-added them.
Carefully.
Then redeployed.
Act V: Silence
The build passed.
The Firebase config appeared.
The dashboard loaded.
No errors.
No warnings.
No screams.
Just… working code.
The Real Horror
The bug wasn’t in my logic.
It wasn’t in Firebase.
It wasn’t in Next.js.
The horror was this:
Cloudflare Pages does not always inject environment variables correctly if they are added before the first successful deployment.
Delete them.
Re-add them.
Redeploy.
And the curse is lifted.
Final Words
There are bugs you fix with code.
And then there are bugs you fix with rituals.
This one wanted sacrifice.
Next time your app insists the environment doesn’t exist-
Believe it.
And start deleting.
Sleep well.