Title: --env-file-if-exists throws error when the .env file doesn't exist and when combined with --watch (now in lts) · Issue #57040 · nodejs/node · GitHub
Open Graph Title: --env-file-if-exists throws error when the .env file doesn't exist and when combined with --watch (now in lts) · Issue #57040 · nodejs/node
X Title: --env-file-if-exists throws error when the .env file doesn't exist and when combined with --watch (now in lts) · Issue #57040 · nodejs/node
Description: Version v22.14.0 v24.13.1, v25.6.1 Platform Linux arch 6.13.2-arch1-1 #1 SMP PREEMPT_DYNAMIC Sat, 08 Feb 2025 18:54:55 +0000 x86_64 GNU/Linux Linux archlinux 6.18.9-zen1-2-zen #1 ZEN SMP PREEMPT_DYNAMIC Mon, 09 Feb 2026 17:45:06 +0000 x8...
Open Graph Description: Version v22.14.0 v24.13.1, v25.6.1 Platform Linux arch 6.13.2-arch1-1 #1 SMP PREEMPT_DYNAMIC Sat, 08 Feb 2025 18:54:55 +0000 x86_64 GNU/Linux Linux archlinux 6.18.9-zen1-2-zen #1 ZEN SMP PREEMPT_DY...
X Description: Version v22.14.0 v24.13.1, v25.6.1 Platform Linux arch 6.13.2-arch1-1 #1 SMP PREEMPT_DYNAMIC Sat, 08 Feb 2025 18:54:55 +0000 x86_64 GNU/Linux Linux archlinux 6.18.9-zen1-2-zen #1 ZEN SMP PREEMPT_DY...
Opengraph URL: https://github.com/nodejs/node/issues/57040
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"--env-file-if-exists throws error when the .env file doesn't exist and when combined with --watch (now in lts)","articleBody":"### Version\n\n~~v22.14.0~~\nv24.13.1, v25.6.1\n\n### Platform\n\n~~Linux arch 6.13.2-arch1-1 #1 SMP PREEMPT_DYNAMIC Sat, 08 Feb 2025 18:54:55 +0000 x86_64 GNU/Linux~~\n```text\nLinux archlinux 6.18.9-zen1-2-zen #1 ZEN SMP PREEMPT_DYNAMIC Mon, 09 Feb 2026 17:45:06 +0000 x86_64 GNU/Linux\n```\n\n### Subsystem\n\n_No response_\n\n### What steps will reproduce the bug?\n\nRun any script in a project where a .env file _**doesn't exist**_:\n\n```bash\nmkdir repro \u0026\u0026 cd repro \u0026\u0026 npm init -y \u0026\u0026 echo \"console.log('repro');\" \u003e main.js\nnode --env-file-if-exists=.env --watch main.js\n```\n\nIf the .env file exists or you don't use the `--watch` flag, script runs normally without throwing errors.\n\n### How often does it reproduce? Is there a required condition?\n\nThese need to be true for the problem to occur:\n\n- use the flag `--env-file-if-exists` pointing to a non existing .env file, like `--env-file-if-exists=.env`\n- use the flag `--watch`\n\n### What is the expected behavior? Why is that the expected behavior?\n\nScript should run normally with the following message being printed right before it:\n\n\u003e .env not found. Continuing without it.\n\n\n### What do you see instead?\n\nAn error stating .env was not found.\n\n```bash\n.env not found. Continuing without it.\nnode:internal/fs/watchers:247\n const error = new UVException({\n ^\n\nError: ENOENT: no such file or directory, watch '/home/mkvlrn/sandbox/repro/.env'\n at FSWatcher.\u003ccomputed\u003e (node:internal/fs/watchers:247:19)\n at watch (node:fs:2550:36)\n at FilesWatcher.watchPath (node:internal/watch_mode/files_watcher:109:21)\n at FilesWatcher.filterFile (node:internal/watch_mode/files_watcher:128:12)\n at start (node:internal/main/watch_mode:78:13)\n at init (node:internal/main/watch_mode:148:15)\n at node:internal/main/watch_mode:160:1 {\n errno: -2,\n syscall: 'watch',\n code: 'ENOENT',\n path: '/home/mkvlrn/sandbox/repro/.env',\n filename: '/home/mkvlrn/sandbox/repro/.env'\n}\n\nNode.js v22.14.0\n.env not found. Continuing without it.\nrepro\nnode:events:496\n throw er; // Unhandled 'error' event\n ^\n\nError: write EPIPE\n at target._send (node:internal/child_process:877:20)\n at target.send (node:internal/child_process:751:19)\n at reportModuleToWatchMode (node:internal/modules/cjs/loader:279:13)\n at Function._load (node:internal/modules/cjs/loader:1097:5)\n at TracingChannel.traceSync (node:diagnostics_channel:322:14)\n at wrapModuleLoad (node:internal/modules/cjs/loader:220:24)\n at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:170:5)\n at node:internal/main/run_main_module:36:49\nEmitted 'error' event on process instance at:\n at node:internal/child_process:881:39\n at process.processTicksAndRejections (node:internal/process/task_queues:85:11) {\n errno: -32,\n code: 'EPIPE',\n syscall: 'write'\n}\n\nNode.js v22.14.0\n```\n\n### Additional information\n\nThis is almost a 100% copy of a previous issue (#56887) I had opened a couple weeks back, but that issue was found on the latest/23 version, while not present in the then current LTS `v22.13.1`. Now it is happening in the LTS `22.14` version. Still working fine in `22.13.1`.\n\n_22.13.1_\n\n\n_22.14_\n","author":{"url":"https://github.com/mkvlrn","@type":"Person","name":"mkvlrn"},"datePublished":"2025-02-13T22:13:48.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/57040/node/issues/57040"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:30c50ba7-782f-11d3-2e0f-9ab835f849d7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D916:A3B49:12488F7:18FB8AB:6A4D6B1C |
| html-safe-nonce | 47659971f602fd8740e30e7aa92ce16f1dce9e02571828ba77c7da266049ab53 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEOTE2OkEzQjQ5OjEyNDg4Rjc6MThGQjhBQjo2QTRENkIxQyIsInZpc2l0b3JfaWQiOiIxNjcyMjcyNzE0MjEzOTc2ODYwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 88eb6ccfe6c2ee6cafaf3686aff73d4d57dace54c412eba4ae16269295066747 |
| hovercard-subject-tag | issue:2852213718 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/57040/issue_layout |
| twitter:image | https://opengraph.githubassets.com/405123438d7d2a030652503d134b304f7c6926ce757765684395c36a4449be4a/nodejs/node/issues/57040 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/405123438d7d2a030652503d134b304f7c6926ce757765684395c36a4449be4a/nodejs/node/issues/57040 |
| og:image:alt | Version v22.14.0 v24.13.1, v25.6.1 Platform Linux arch 6.13.2-arch1-1 #1 SMP PREEMPT_DYNAMIC Sat, 08 Feb 2025 18:54:55 +0000 x86_64 GNU/Linux Linux archlinux 6.18.9-zen1-2-zen #1 ZEN SMP PREEMPT_DY... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mkvlrn |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7db3950e3f59095e20a9789440c3dd554efc62d434882ead06ae05b5815605b9 |
| turbo-cache-control | no-preview |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | cd8f6a71db61d6012a0cbb134be844fdbe9b8a45 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width