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?

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.

3 participants