Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start.sh doesn't pre-load environment variables anymore - this breaks automatic VITE_* environment variables in frontend #2227

Open
egor-yudkin opened this issue Dec 11, 2024 · 4 comments

Comments

@egor-yudkin
Copy link

This issue is for a: (mark with an x)

- [ ] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [x] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

  1. Add some frontend code that is using VITE_* environment variable
  2. Run start.sh script
  3. Observe that VITE_* values are empty

Any log messages given by the failure

none

Expected/desired behavior

start.sh script used to import environment variables from azd environment at the beginning. It would be nice to be able to load env values before starting frontend.
start.ps1 doesn't have this problem.

OS and Version?

Linux Ubuntu 22.04

azd version?

1.11.0

Mention any other details that might be useful

I realize that this behavior is impacting only a customization that I've made in my fork. We are using a few VITE_* variables to change some UI elements depending on the environment we run the application in.

The start.sh change was made in PR #1986 to remove an anti-pattern. I'm not asking to revert it, but maybe you can suggest how to load specific environment variables before starting the frontend?
Or maybe I'm doing it wrong and should not rely on VITE_* variables at all.

Thanks!

@pamelafox
Copy link
Collaborator

Hm, were you setting those VITE_ variables using azd env set or export? If you're setting them via export, then they should keep working fine. I only expected devs to be setting azd-related variables via azd env set.

Another thing you may want to do, if you're using VS Code, is to use the VS Code run & debug instead, and add those VITE variables in .vscode/launch.json. I personally avoid using the start scripts, since they're fairly slow to start, don't do hot reloading, etc.

@egor-yudkin
Copy link
Author

egor-yudkin commented Dec 12, 2024

I set them with azd env set and also put them into a bicep file for pushing into an app service.

I haven't used VS Code run & debug option, but isn't .vscode/launch.json going to remain the same when I switch azd env? My use case is to have different VITE environment values for different azd env

For now I've just restored the code for env variables in start.sh, but added a filter to do export only of VITE variables

@pamelafox
Copy link
Collaborator

Ah, okay, I didn't appreciate that you used them for deployment and vary them per environment.

If you want to send a PR for your vite change, we could make that change in the main branch as well. That's reasonable that you need access to VITE_ variables in the frontend.

@egor-yudkin
Copy link
Author

@pamelafox I've submitted the PR for this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants