Skip to content

repl: reject --watch without script#64306

Open
iclectic wants to merge 1 commit into
nodejs:mainfrom
iclectic:fix-watch-requires-file
Open

repl: reject --watch without script#64306
iclectic wants to merge 1 commit into
nodejs:mainfrom
iclectic:fix-watch-requires-file

Conversation

@iclectic

@iclectic iclectic commented Jul 5, 2026

Copy link
Copy Markdown

Fixes: #64135

This updates watch mode option validation so that node --watch without a script exits with an option error instead of falling through to the REPL.

Previously, the validation checked whether the argument list had fewer than one item. However, the argument list still contains the Node executable itself, so node --watch was not treated as missing a script. The check now requires at least two arguments, meaning the executable plus a script file.

A regression test has been added to confirm that node --watch:

  • exits with code 9
  • prints --watch requires specifying a file
  • does not write to stdout

Tested with:

$ ./node --watch < /dev/null
./node: --watch requires specifying a file

$ ./node --test --test-name-pattern="require a file to watch" test/sequential/test-watch-mode-watch-flags.mjs
✔ should require a file to watch

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/config

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. config Issues or PRs related to the config subsystem needs-ci PRs that need a full CI run. labels Jul 5, 2026

@MoLow MoLow left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@aduh95

aduh95 commented Jul 5, 2026

Copy link
Copy Markdown
Contributor
Test failure: 'should watch changes to a file from config file'
Location: test/sequential/test-watch-mode.mjs:872:3
AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
+ actual - expected

+ '/Users/runner/work/node/node/node/out/Release/node: --watch requires specifying a file\n'
- ''

    at TestContext.<anonymous> (file:///Users/runner/work/node/node/node/test/sequential/test-watch-mode.mjs:881:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:104:5)
    at async Test.run (node:internal/test_runner/test:1389:7)
    at async Suite.processPendingSubtests (node:internal/test_runner/test:960:7) {
  generatedMessage: true,
  code: 'ERR_ASSERTION',
  actual: '/Users/runner/work/node/node/node/out/Release/node: --watch requires specifying a file\n',
  expected: '',
  operator: 'strictEqual',
  diff: 'simple'
}

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

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. config Issues or PRs related to the config subsystem needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Does/should the REPL support --watch?

4 participants