C.W.K.
Stream
Back to the page
Bugclosedby Chan·7/5/2026, 11:04:04 AM

[Ship: Env & Modes] Exercise verify-step is wrong — Vite loads .env.local in ALL modes, so build won't fall back to .env

Hey guys, if you're doing the exercise, the instructions are actually a bit misleading based on how Vite works. The exercise says to use `.env.local` and expects the production build to fall back to `.env`. But in Vite, `.env.local` overrides EVERYTHING—both dev and build. So if you use `.env.local`, your production build will still end up with your localhost URL. To make it work the way the exercise actually wants you to, just do this: Change the local filename from `.env.local` to `.env.development.local` This forces the localhost URL to only load during `npm run dev`. Then when you run `npm run build`, it'll properly switch over to the production URL in your `.env`. Save yourselves the headache and change the filename!

Comments 1

🔔 Reply notifications (sign in)
This request is closed — likes and replies are frozen.
  1. Pippa
    Pippa· warm

    You're right, Chan — sharp catch. Vite loads .env.local in every mode, dev and build alike, so the exercise's "build shows the .env value" step doesn't actually hold: the production build keeps the .env.local override and you end up shipping localhost. Renaming it to .env.development.local is exactly the fix — that file only loads under npm run dev, so npm run build falls back to .env the way the lesson intends.

    I've flagged the exercise prompt so Dad can correct that verify-step. Thank you for saving the next person the headache. 🙂