Repository navigation
--env-file-if-exists throws error when the .env file doesn't exist and when combined with --watch #56887
Copy link
Copy link
Closed
Labels
dotenvIssues and PRs related to .env file parsing.Issues and PRs related to .env file parsing.watch-modeIssues and PRs related to watch mode.Issues and PRs related to watch mode.
Description
Version
23.7.0
Platform
Linux fedora 6.12.11-200.fc41.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Jan 24 04:59:58 UTC 2025 x86_64 GNU/Linux
Subsystem
No response
What steps will reproduce the bug?
Run any script in a project where a .env file doesn't exist:
node --env-file-if-exists=.env --watch main.jsIf the .env file exists or you don't use the --watch flag, script runs normally without throwing errors.
How often does it reproduce? Is there a required condition?
These need to be true for the problem to occur:
- use the flag
--env-file-if-existspointing to a non existing .env file,--env-file-if-exists=.env - use the flag
--watch
What is the expected behavior? Why is that the expected behavior?
Script should run normally with the following message being printed right before it:
.env not found. Continuing without it.
What do you see instead?
An error stating .env was not found.
.env not found. Continuing without it.
node:internal/fs/watchers:247
const error = new UVException({
^
Error: ENOENT: no such file or directory, watch '/home/mkvlrn/github/template-discordbot/.env'
at FSWatcher.<computed> (node:internal/fs/watchers:247:19)
at watch (node:fs:2551:36)
at FilesWatcher.watchPath (node:internal/watch_mode/files_watcher:109:21)
at FilesWatcher.filterFile (node:internal/watch_mode/files_watcher:128:12)
at start (node:internal/main/watch_mode:78:13)
at init (node:internal/main/watch_mode:148:15)
at node:internal/main/watch_mode:160:1 {
errno: -2,
syscall: 'watch',
code: 'ENOENT',
path: '/home/mkvlrn/github/template-discordbot/.env',
filename: '/home/mkvlrn/github/template-discordbot/.env'
}
Node.js v23.7.0
.env not found. Continuing without it.
node:events:485
throw er; // Unhandled 'error' event
^
Error: write EPIPE
at target._send (node:internal/child_process:877:20)
at target.send (node:internal/child_process:751:19)
at #createModuleJob (node:internal/modules/esm/loader:552:15)
at #getJobFromResolveResult (node:internal/modules/esm/loader:312:34)
at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:280:41)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:582:25)
Emitted 'error' event on process instance at:
at node:internal/child_process:881:39
at process.processTicksAndRejections (node:internal/process/task_queues:85:11) {
errno: -32,
code: 'EPIPE',
syscall: 'write'
}
Node.js v23.7.0Additional information
Neither --watch nor --env-file /--env-file-if-exists documentations warn about not combining these flags.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
dotenvIssues and PRs related to .env file parsing.Issues and PRs related to .env file parsing.watch-modeIssues and PRs related to watch mode.Issues and PRs related to watch mode.
Activity
[-]--env-file-if-exists throws error when the .env file doesn't exist if paired with --watch[/-][+]--env-file-if-exists throws error when the .env file doesn't exist when combined with --watch[/+][-]--env-file-if-exists throws error when the .env file doesn't exist when combined with --watch[/-][+]--env-file-if-exists throws error when the .env file doesn't exist and when combined with --watch[/+]juanarbol commentedon Feb 3, 2025
Interesting...
doc: mark `--env-file-if-exists` flag as experimental
juanarbol commentedon Feb 3, 2025
This seems to be fixed in upstream.
./node --env-file-if-exists=.env --watch main.js .env not found. Continuing without it. .env not found. Continuing without it. Hola mundo Completed running 'main.js'Thanks for this report, please make sure you use LTS releases. See https://github.com/nodejs/release?tab=readme-ov-file#release-schedule
This bug is fixed in v22.13.1.
$ node -v v22.13.1 $ node --env-file-if-exists=.env --watch main .env not found. Continuing without it. .env not found. Continuing without it. Hola mundo Completed running 'main'I'll proceed to close this issue as it is fixed and released
mkvlrn commentedon Feb 3, 2025
Thanks for looking into it. I was using latest (23) because of the removal of the --experimental-strip-types flag and never even tried with LTS - that was a terrible oversight of mine. Too excited to run those ts files!
juanarbol commentedon Feb 3, 2025
Please be careful :)
doc: mark `--env-file-if-exists` flag as experimental
doc: mark `--env-file-if-exists` flag as experimental
doc: mark `--env-file-if-exists` flag as experimental
aduh95 commentedon Feb 14, 2025
@juanarbol rather than pushing users off of Current releases (we want users to use Current releases, it's the whole point of having them), it would more useful to use the report to tag the relevant folks and make sure the bug doesn't make its way into an LTS release – which has happen, see #57040
doc: mark `--env-file-if-exists` flag as experimental
doc: mark `--env-file-if-exists` flag as experimental
doc: mark `--env-file-if-exists` flag as experimental
doc: mark `--env-file-if-exists` flag as experimental