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

deno run --env fails when no .env file is present. #21788

Closed
marvinhagemeister opened this issue Jan 4, 2024 · 4 comments · Fixed by #21879
Closed

deno run --env fails when no .env file is present. #21788

marvinhagemeister opened this issue Jan 4, 2024 · 4 comments · Fixed by #21879

Comments

@marvinhagemeister
Copy link
Contributor

In Fresh we recently switched from using std's dotenv module to Deno's --env in denoland/fresh#2204 . But we noticed that passing --env when no .env file is present will exit the current process with an error message.

error: Unable to load '.env' environment variable file

With the dotenv module it didn't error when no .env file was present.

Steps to reproduce

  1. Create a file foo.ts (can be empty)
  2. Run deno run -A --env foo.ts

Version: Deno 1.39.1

@bartlomieju
Copy link
Member

I think we did this on purpose when landing --env flag. @dsherret do you happen to remember this?

@dsherret
Copy link
Member

dsherret commented Jan 4, 2024

Nope. I feel like it shouldn't error.

@iuioiua
Copy link
Contributor

iuioiua commented Jan 5, 2024

This was done on purpose. Should we instead print a gentle message saying that no .env file was detected?

deno/cli/args/mod.rs

Lines 723 to 727 in aadcd64

if let Some(env_file_name) = &flags.env_file {
if (from_filename(env_file_name)).is_err() {
bail!("Unable to load '{env_file_name}' environment variable file")
}
}

@bartlomieju
Copy link
Member

@iuioiua that makes sense. Any chance you could fix it and open a PR?

bartlomieju pushed a commit that referenced this issue Jan 21, 2024
Uses similar format to when the latest version of std is implicitly
being used.

Closes #21788
bartlomieju pushed a commit to bartlomieju/deno that referenced this issue Jan 22, 2024
Uses similar format to when the latest version of std is implicitly
being used.

Closes denoland#21788
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

Successfully merging a pull request may close this issue.

4 participants