W
Wasp3d ago
Gökhan

Wasp is not updating the .env variables.

Even with wasp clean, it doesn't seem to update env file. When I build my project, it connects to nonexistant (but I had it before) backend link from the client. I've set it to localhost now, but it doesn't care. I am using REACT_APP_API_URL in the .env.client . It connects to my old railway production backend.
2 Replies
kapa.ai
kapa.ai3d ago
Hi @Gökhan. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the knowledge sources, here’s what’s likely happening: - In Wasp, client environment variables (like REACT_APP_API_URL) are embedded into the client code at build time. This means that whatever value is present when you run the build command (e.g., wasp build) is what gets hardcoded into your frontend bundle. Updating the .env.client file after building will not affect the already-built client code—you must rebuild for changes to take effect. - During development, Wasp picks up changes from .env.client when you restart the dev server (wasp start). In production, you must ensure the correct value is present in .env.client (or provided via the shell) before running wasp build. If you build with the wrong value, the old value will persist in your built frontend, even if you later update .env.client and rebuild without cleaning the build directory. - The docs recommend providing client env vars by setting them before the build command, e.g.:
REACT_APP_API_URL=<http://localhost:3001> wasp build

REACT_APP_API_URL=<http://localhost:3001> wasp build

or by updating .env.client and then running wasp build. Make sure you are editing the correct .env.client file in your project root, and that you are running wasp build after making changes. If you are using a deployment script or CI/CD, double-check that the correct env vars are being set at build time Defining Env Vars in Production. - If you are still seeing the old value after running wasp clean and wasp build, it’s possible that: - The .env.client file is not being picked up (wrong location, typo, etc.). - The build output is not being properly deployed or served (e.g., you are serving an old build). - You are not actually running wasp build after updating the env var. Troubleshooting steps: 1. Double-check that .env.client is in your project root and contains the correct value:
REACT_APP_API_URL=<http://localhost:3001>

REACT_APP_API_URL=<http://localhost:3001>

2. Run wasp clean to remove previous builds. 3. Run wasp build to rebuild the project. 4. Deploy or serve the newly built frontend. If you are deploying manually (e.g., to Railway), make sure you are copying and deploying the latest build artifacts as described in the deployment docs Deploying the Client. Key point:
Client env vars are only embedded at build time. Changing .env.client after building has no effect until you rebuild. If you follow the above steps and still see the old value, double-check your deployment process and ensure you are not serving a cached or outdated build. For more details, see the official docs: Env Variables and Defining Env Vars in Production. If you continue to have issues, please provide the exact steps you are taking, including file locations and build/deploy commands, so we can help further. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Gökhan, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Filip
Filip22h ago
Hey @Gökhan, we need more details here too. Please list the steps you do to get this problem (what do you set and where, etc.), in detail. I'll then try to reproduce it 🙂

Did you find this page helpful?