-
Notifications
You must be signed in to change notification settings - Fork 49
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
The dotenv! macro looks for the .env in the workspace root dir instead of crate root dir #74
Comments
Hi Steve, I was able to reproduce your problem. allan2/dotenvy-workspace-example The issue is that One solution is to use let manifest_dir = std::env::var("CARGO_MANIFEST_DIR")?;
dotenvy::from_path(format!("{manifest_dir}/.env"))?;
std::env::var("FOO")?; Of course, this loads at runtime instead of compile time. Let me know if that is acceptable for you. |
I was hoping to use the |
Has anyone found a reasonable solution to this problem? In my case the .env file needs to be in the parent directory as other language projects will use it. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Any fix for this? This should at least be documented. I was banging my head against the wall as to why the rust analyzers macro expansion was fine, but cargo build failed. |
What I do personally is,
In code I do this:
So that I can make io error (“file not found”) logged at info level and not fatal, but errors in the env file format are loud. And for The main limitation is that the symlink scheme might not work perfectly on windows but that hasn’t been a problem for me since that’s not primarily where we develop or build releases. The symlink idea might help for the situations described -- but I don't use the |
Looking some more: it looks that the proc macro implementation for https://docs.rs/dotenvy_macro/0.15.7/src/dotenvy_macro/lib.rs.html#17 However,
https://users.rust-lang.org/t/which-directory-does-a-proc-macro-run-from/71917/4 So it looks to me that, what happens when you use |
I commonly work in a workspace with multiple binary crates that each have their own .env file. However it seems the
dotenv!()
macro is looking for the .env file in the workspace root instead of the crate root dir.Any idea why this would be happening?
The text was updated successfully, but these errors were encountered: