From bd87d0dc43aa40509eb8f6bd6d39a14ba652f5c8 Mon Sep 17 00:00:00 2001 From: anshikakalpana Date: Tue, 23 Jun 2026 14:36:44 +0530 Subject: [PATCH] watch: fix missing file error when --watch used without argument Signed-off-by: anshikakalpana --- lib/internal/main/watch_mode.js | 5 +++++ test/parallel/test-watch-mode-requires-file.mjs | 7 +++++++ 2 files changed, 12 insertions(+) create mode 100644 test/parallel/test-watch-mode-requires-file.mjs diff --git a/lib/internal/main/watch_mode.js b/lib/internal/main/watch_mode.js index e864dfad1b84de..d5235f2c636a2c 100644 --- a/lib/internal/main/watch_mode.js +++ b/lib/internal/main/watch_mode.js @@ -31,6 +31,11 @@ const { once } = require('events'); prepareMainThreadExecution(false, false); markBootstrapComplete(); +if (!process.argv[1]) { + process.stderr.write('node: --watch requires specifying a file\n'); + process.exit(9); +} + const kKillSignal = convertToValidSignal(getOptionValue('--watch-kill-signal')); const kShouldFilterModules = getOptionValue('--watch-path').length === 0; const kEnvFiles = getOptionValue('--env-file'); diff --git a/test/parallel/test-watch-mode-requires-file.mjs b/test/parallel/test-watch-mode-requires-file.mjs new file mode 100644 index 00000000000000..34e54fce397c4b --- /dev/null +++ b/test/parallel/test-watch-mode-requires-file.mjs @@ -0,0 +1,7 @@ +import '../common/index.mjs'; +import { spawnSync } from 'node:child_process'; +import assert from 'node:assert'; + +const result = spawnSync(process.execPath, ['--watch'], { encoding: 'utf8' }); +assert.strictEqual(result.status, 9); +assert.match(result.stderr, /--watch requires specifying a file/);