fix: restore --env-file parent directory traversal and do not error in deno compile for not found env file#32686
Merged
dsherret merged 10 commits intodenoland:mainfrom Mar 13, 2026
Conversation
When dotenvy was replaced with deno_dotenv in denoland#32263, the parent directory traversal behavior of `dotenvy::from_filename()` was lost. This caused `--env-file` to no longer find .env files in parent directories when running from a subdirectory. Adds `find_env_file()` which walks up parent directories looking for the named file, restoring the previous behavior. Closes denoland#32683 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The .env file in the env_file_parent_traversal spec test was not tracked by git due to the repo-level .gitignore rule, causing CI failures across all platforms. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
dsherret
suggested changes
Mar 13, 2026
cli/util/env.rs
Outdated
Comment on lines
+19
to
+20
| /// looking for a file with the same name. This replicates the behavior of | ||
| /// dotenvy's `find()` function that was lost when switching to deno_dotenv. |
cli/util/env.rs
Outdated
Comment on lines
+35
to
+36
| #[allow(clippy::disallowed_methods)] | ||
| env::current_dir().ok() |
Contributor
There was a problem hiding this comment.
I'm going to clean up this PR. Too many things to discuss.
deno compile for not found env file
dsherret
approved these changes
Mar 13, 2026
Contributor
dsherret
left a comment
There was a problem hiding this comment.
LGTM. I hand wrote this.
dsherret
reviewed
Mar 13, 2026
| ); | ||
|
|
||
| // should load fine as in Node.js | ||
| process.loadEnvFile(envFilePath); |
Contributor
There was a problem hiding this comment.
This previously wasn't working like node.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
dotenvywithdeno_dotenv#32263 where replacingdotenvywithdeno_dotenvlost the parent directory traversal behavior for--env-filefind_env_file()helper that walks up parent directories when the specified env file isn't found at the given path, restoring thedotenvy::from_filename()behaviordeno compileCloses #32683
Closes #30402
Test plan
env_file_parent_traversalverifies.envin parent dir is found when running from subdirectoryenv_filespec tests continue to pass🤖 Generated with Claude Code