Skip to content
FunnelGuard

Fix guide by FunnelsGuard

Environment variable missing after redeploy: how to find and fix it

OPS-299High impactDetectedBy FunnelGuardPublished Updated
On this page

What this issue is

An environment variable is a named value your app reads when it builds or runs, for example STRIPE_SECRET_KEY, CRM_API_URL or GTM_ID. It keeps secrets and per-environment settings out of your code.

After a redeploy the variable can be gone or empty. Common causes: it was only set for Preview, not Production; it was added in a dashboard after the last build, so the running build never saw it; it was renamed in code but not in the host; the project was moved or recreated; or a deploy script overwrote the .env file.

Why it costs you leads or sales

The pages look normal, so nobody complains until the numbers drop. Typical effects depend on which variable vanished:

What a missing variable can break
Variable typeWhat goes wrongWhat you see
Email or SMTP keyForm submits but no notification is sentEmpty inbox, happy-looking thank-you page
CRM or webhook URLLeads are not savedGaps in CRM records
Payment keyCheckout errors or hangsFewer orders
Tracking or tag IDTag loads with no ID, or not at allConversions vanish in GA4 or ad platforms
Public API key (maps, chat, booking)Widget fails to loadMissing button or blank embed
Where a missing variable breaks the journey
  1. Ad clickVisitor lands on the page
  2. Page loadsLooks normal after redeploy
  3. Form submitServer reads an undefined API key
  4. Lead reaches CRMNever arrives
  5. Conversion trackedNever fires

The page loads, so the break is hidden until the form step.

Leads per day around a redeployExample numbers
Leads per day around a redeploy (example)Before deploy: 12 leads; Deploy day: 5 leads; Day 2: 0 leads; Day 3: 0 leads; After fix: 12 leads0591250012Before deployDeploy dayDay 2Day 3After fixleads

Example: illustrative numbers. Leads drop to zero in the CRM the day the variable disappears and stay there until someone notices.

How to check if your site has it

Check for a missing variable
  1. Compare the deploy to the last good one

    Open your host's deploy log. Note the time of the first deploy after things last worked and what changed.

  2. List variables for the Production environment

    In your host's settings (for example Environment Variables in Vercel, Netlify or Render), check each variable your code needs exists for Production, not just Preview or Development.

  3. Check the build log for warnings

    Search for words such as undefined, missing, not set or cannot read. Many frameworks print a warning or fail the build when a required value is absent.

  4. Check build-time versus run-time

    Public values baked into the front end (for example names starting NEXT_PUBLIC_ or VITE_) are read at build time. If you added them after the last build, rebuild.

  5. Run the journey yourself

    Submit your own form, start a checkout to the payment step, and check the inbox, CRM and your analytics real-time report.

Fail loudly when a required variable is missingjavascript
const required = ['CRM_API_URL', 'CRM_API_KEY', 'SMTP_HOST'];
const missing = required.filter((name) => !process.env[name]);
if (missing.length) {
  throw new Error('Missing environment variables: ' + missing.join(', '));
}

How to fix it

Restore the variable by platform
  1. Add the variable to the right environment

    Open your host's project settings, find Environment Variables, and add the name and value for Production. Check the spelling matches the code exactly, including case.

  2. Redeploy with a fresh build

    Trigger a new build. Existing builds do not pick up new values, and build-time variables are only baked in during the build.

  3. Check server files

    On a server you manage, confirm the .env file or systemd or Docker environment settings survived the deploy, and that your deploy script does not overwrite them.

How to confirm it's fixed

Confirmation checks
  • The new deploy finished and used the latest variables
  • Test form submission arrives in the inbox
  • The test lead appears in the CRM
  • Checkout reaches the payment step without errors
  • The conversion shows in GA4 real-time or the ad platform's test tool
  • The browser console shows no failed requests to your own API

How to prevent it happening again

Prevention habits
  • Keep a documented list of every variable the site needs, per environment
  • Add a startup check that fails the build when a required variable is missing
  • Copy variables to Production when you add them to Preview
  • Avoid renaming variables without updating the host in the same change
  • Store secrets in a password manager or secrets service, not only in one dashboard
  • Test the real journey right after every deploy
  • Avoid deploying during peak ad hours
Deploy without and with a variable check

No check

  • Deploy succeeds
  • Form sends nothing
  • You find out from missing leads days later

With a check and a journey test

  • Build fails or the test fails within minutes
  • You restore the variable
  • Few or no leads lost

How FunnelGuard handles this

FunnelGuard detects this today, as a visible failure rather than a direct check of your settings. It does not read your environment variables. Instead, a robot visitor runs your real journeys on a schedule, such as the lead form, checkout or booking button, and checks each step, the tracking hits sent to platforms like GA4, Google Ads and Meta, and whether the test lead reaches the inbox and CRM.

Redeploy, then a silent failure

The page loads but the form step fails because a value is missing.

Questions people ask

Why is my environment variable undefined after redeploy?

It is usually set on a different environment (Preview instead of Production), added after the last build, or named differently from what the code reads. Check the Production environment settings, match the exact name, and trigger a fresh build.

Why is my form not sending emails after a deploy?

The SMTP or email API key may be missing in the new deploy, so the code skips sending while the thank-you page still shows. Confirm the variables exist for Production, redeploy, and send a test submission.

Do I need to rebuild after adding an environment variable?

Yes, in most hosts. Existing builds do not pick up new values, and public front-end variables are baked in at build time. Trigger a new deploy after any change.

How do I find out which environment variable is missing?

Compare your list of required variables with the Production settings, and read the build log for undefined or missing warnings. A startup check that lists missing names makes this much faster.

Can a missing environment variable break tracking?

Yes. If a measurement or tag ID comes from a variable, the tag may load without an ID or not at all, and conversions stop appearing in analytics and ad platforms.

How can I catch this before customers notice?

Run a real journey test after each deploy and on a schedule: submit the form, then check the inbox, CRM and tracking. A synthetic monitor such as FunnelGuard does this automatically and alerts you when a step fails.

Does FunnelGuard read my environment variables?

No. It detects the effect: it runs your journeys, sees the failing step, missing tracking hit or lead that never arrives, and alerts you with a screenshot and likely cause.

Does FunnelGuard catch this?

Detected

FunnelGuard checks for this today.

How: Visible as failures.

Stop finding out from your customers

FunnelGuard runs your real forms and checkouts on a schedule, checks the tracking and the leads behind them, and alerts you once, with a screenshot. Try any paid plan free for 3 days.