Skip to content

src: fix missing file error when --watch used without argument#62334

Open
nickshiro wants to merge 1 commit intonodejs:mainfrom
nickshiro:nick-watch-mode
Open

src: fix missing file error when --watch used without argument#62334
nickshiro wants to merge 1 commit intonodejs:mainfrom
nickshiro:nick-watch-mode

Conversation

@nickshiro
Copy link

Problem

Previously, running node --watch without specifying a file would
start the REPL instead of exiting with code 9. This was a regression
found in issue #62305.

Solution

  • Add an explicit check for process.argv[1] immediately after
    markBootstrapComplete(). If no file is provided, print the
    original error message and exit with code 9.
  • Add new test test/parallel/test-watch-mode-without-file.mjs for check error message and exit with correct code.

@nodejs-github-bot nodejs-github-bot added the needs-ci PRs that need a full CI run. label Mar 19, 2026
@Renegade334
Copy link
Member

The --watch argument checks are here:

node/src/node_options.cc

Lines 258 to 271 in 56aba88

if (watch_mode) {
if (syntax_check_only) {
errors->push_back("either --watch or --check can be used, not both");
} else if (has_eval_string) {
errors->push_back("either --watch or --eval can be used, not both");
} else if (force_repl) {
errors->push_back("either --watch or --interactive "
"can be used, not both");
} else if (test_runner_force_exit) {
errors->push_back("either --watch or --test-force-exit "
"can be used, not both");
} else if (!test_runner && watch_mode_paths.empty() && argv->size() < 1) {
errors->push_back("--watch requires specifying a file");
}

The last of these is what needs fixing.

@nickshiro
Copy link
Author

Both ./node --watch (CLI) and config-file parsing pass
produce identical state in CheckOptions:

  • watch_mode = true
  • argv = ['./node'] (size=1)
  • experimental_config_file_path = '' (not yet parsed)
  • experimental_default_config_file = false

--watch is consumed by the parser before CheckOptions runs,
so we can't detect it in orig_args either.

What's the intended approach to distinguish these two cases
within node_options.cc / CheckOptions? Should we add a field to EnvironmentOptions to track
whether watch_mode was set from CLI vs config?

@codecov
Copy link

codecov bot commented Mar 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.68%. Comparing base (56aba88) to head (6c15719).
⚠️ Report is 34 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #62334      +/-   ##
==========================================
- Coverage   91.64%   89.68%   -1.97%     
==========================================
  Files         337      676     +339     
  Lines      140643   206579   +65936     
  Branches    21810    39554   +17744     
==========================================
+ Hits       128893   185264   +56371     
- Misses      11526    13460    +1934     
- Partials      224     7855    +7631     

see 458 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants