fix: route _log/_debug to stderr, simplify LINE regex, add troubleshooting docs#938
Closed
sudip-kumar-prasad wants to merge 1 commit intomotdotla:masterfrom
Closed
Conversation
…eshooting docs
- Route _log() and _debug() output to console.error (stderr) instead of
console.log (stdout). Diagnostic messages pollute stdout and break shell
piping (e.g. node app.js | jq would include log output in the data stream).
- Simplify the LINE regex: replace redundant (?:^|^) / (?:$|$) alternations
with plain ^ / $ anchors. The original groups were logically identical to
their simplified form and served no functional purpose.
- Add a Troubleshooting section to README.md covering two very common user
pain points:
1. Existing env vars not being overwritten (by design) and how to use
{ override: true } to bypass this.
2. .env file not loading and how to enable debug mode to diagnose it.
- Update all test stubs in test-config.js, test-config-vault.js, and
test-populate.js from sinon.stub(console, 'log') to
sinon.stub(console, 'error') to match the new stderr output.
All 194 tests pass.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves dotenv’s runtime diagnostics and documentation by ensuring status/debug output doesn’t pollute stdout, simplifying the line-parsing regex, and adding end-user troubleshooting guidance.
Changes:
- Route
_log()/_debug()output tostderr(viaconsole.error) to keepstdoutclean for piping/redirects. - Simplify the
LINEregex used for parsing.envcontent by removing redundant anchors. - Add a new “Troubleshooting” section to the README with common resolution steps.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test-populate.js | Update tests to stub console.error (matching new stderr logging behavior). |
| tests/test-config.js | Update logging-related tests to stub console.error instead of console.log. |
| tests/test-config-vault.js | Update vault-config tests to stub console.error for warnings/logs. |
| lib/main.js | Switch _debug/_log to console.error and simplify the LINE parsing regex. |
| README.md | Add troubleshooting guidance for common dotenv configuration/loading issues. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
motdotla
reviewed
Feb 26, 2026
| return supportsAnsi() ? `\x1b[2m${text}\x1b[0m` : text | ||
| } | ||
|
|
||
| const LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg |
Owner
There was a problem hiding this comment.
i like this part of the regex - because i like that it looks like a cat. i've mentioned this before and plan to keep it.
Owner
|
not significant enough of a change. doesn't add much value and could break things given historical artifact. |
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
This PR addresses three independent improvements to the dotenv codebase.
Fix 1: Route _log and _debug output to
stderrProblem: _log() and _debug() both used
console.log, which writes tostdout. This causes diagnostic/status messages to pollute the standard output stream, breaking common shell patterns like: