You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support --env-file-if-exists (no error thrown sans .env file) #23323
In addition to the existing --env-file feature, Node also has --env-file-if-exists, which does not throw an error if the given file does not exist. This is particularly useful in dev/lifecycle scripts/CI etc.
Hi @danielbayley, thanks for opening an issue. Can you say a bit more about your use case, and how you end up hitting the failure mode here?
I think my main concern with this is that "if" in CLI flags is usually a code smell: a flag enables or disables something conventionally, so an "if" means that the flag is actually a second order condition (it enables/disables something if something else is the case).
Can you say a bit more about your use case, and how you end up hitting the failure mode here?
Hi @woodruffw, sure, it’s useful e.g. to be able to run the same executable script, with the above bang line, both locally (reading environment variables from .env — which as you undoubtedly know, should never be commited…), and in CI/GitHub Action workflows (where there is no .env, and these should instead be read from repository secrets).
I think my main concern with this is that "if" in CLI flags is usually a code smell: a flag enables or disables something conventionally, so an "if" means that the flag is actually a second order condition (it enables/disables something if something else is the case).
You can call it something else, whatever you like, just allow the option to not throw an error when no .env file exists…
Can you work around this by touch .env in your CI job?
I guess, that‘s a bit hacky though… Also, this is just one example. Another question is, should the existing --env-file even throw an error if a given file does not exist, as opposed to a warning?
Activity
woodruffw commentedon Nov 20, 2026
Hi @danielbayley, thanks for opening an issue. Can you say a bit more about your use case, and how you end up hitting the failure mode here?
I think my main concern with this is that "if" in CLI flags is usually a code smell: a flag enables or disables something conventionally, so an "if" means that the flag is actually a second order condition (it enables/disables something if something else is the case).
danielbayley commentedon Nov 24, 2026
Hi @woodruffw, sure, it’s useful e.g. to be able to run the same executable script, with the above bang line, both locally (reading environment variables from
.env— which as you undoubtedly know, should never becommited…), and in CI/GitHub Action workflows (where there is no.env, and these should instead be read from repositorysecrets).You can call it something else, whatever you like, just allow the option to not throw an error when no
.envfile exists…Also, I mean, if it’s good enough for Node.js…
BurntSushi commentedon Nov 24, 2026
Can you work around this by
touch .envin your CI job?danielbayley commentedon Nov 24, 2026
I guess, that‘s a bit hacky though… Also, this is just one example. Another question is, should the existing
--env-fileeven throw an error if a given file does not exist, as opposed to a warning?woodruffw commentedon Nov 24, 2026
I think it should, but even before we reach that: changing it to a warning would be a breaking change on uv's side.
(FWIW, I think an empty
.envfile is less of a hack than a "maybe" CLI flag.)