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

Variable expansion in .env does not work any more #47

Closed
Frankitch opened this issue Jun 9, 2023 · 4 comments
Closed

Variable expansion in .env does not work any more #47

Frankitch opened this issue Jun 9, 2023 · 4 comments

Comments

@Frankitch
Copy link

Frankitch commented Jun 9, 2023

It seems that since the 16.1, variable expansion does not work anymore.

# .env file

MY_ENV=develop

NG_APP_URL=https://${MY_ENV}.example.com

NG_APP_URL used to be https://develop.example.com until 16.0.2 and now it is https://${MY_ENV}.example.com

By the way, thanks for this great project!
👍

@chihab
Copy link
Owner

chihab commented Jun 9, 2023

I am not able to reproduce the issue.
image

Could you please test in a freshly generated angular project? If you can reproduce it, it would helpful to share that repo.

Thanks for your feedback.

@Frankitch
Copy link
Author

Frankitch commented Jun 11, 2023

On a fresh nx install I cannot reproduce the problem either but on my project if I'm switching between 16.0.2 and 16.1, it works / it does work, that is weird... I have noticed that dotenv dependencies have changed between those versions but I can't understand what causes my trouble.

@Frankitch
Copy link
Author

@chihab I think I spotted the issue: the expansion does not work in the .env located at the root of the (nx) workspace, if I copy the .env file to the sources of the application then it works.

@chihab
Copy link
Owner

chihab commented Jan 7, 2024

That's right, that happens because you run the application using nx command (with a target); when doing that nx does read the .env file and populates process.env before running the @ngx-env/builder, when he builder is run it won't override the env var since already present in process.env.

If you run the builder directly (wihtout using the nx command), you won't have the issue.

The only workaround is to name .env files differently so that nx does not seem them, for example .env.app or the like, you can specify the list of files using the "files".

There is a nx working example in the examples folder.

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