From 6c15719d9b29206b65410e56e7255474890aa6b7 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 19 Mar 2026 12:03:34 +0300 Subject: [PATCH] fix: missing file error when --watch used without argument --- lib/internal/main/watch_mode.js | 5 +++++ test/parallel/test-watch-mode-without-file.mjs | 9 +++++++++ 2 files changed, 14 insertions(+) create mode 100644 test/parallel/test-watch-mode-without-file.mjs diff --git a/lib/internal/main/watch_mode.js b/lib/internal/main/watch_mode.js index 06c2c8602da444..a6052852a9182c 100644 --- a/lib/internal/main/watch_mode.js +++ b/lib/internal/main/watch_mode.js @@ -32,6 +32,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 = [ diff --git a/test/parallel/test-watch-mode-without-file.mjs b/test/parallel/test-watch-mode-without-file.mjs new file mode 100644 index 00000000000000..543cb5c55b79a7 --- /dev/null +++ b/test/parallel/test-watch-mode-without-file.mjs @@ -0,0 +1,9 @@ +'use strict'; + +import { spawnSync } from 'child_process'; +import { strictEqual, match } from "node:assert"; + +const result = spawnSync(process.execPath, ['--watch'], { encoding: 'utf8' }); + +strictEqual(result.status, 9); +match(result.stderr, /--watch requires specifying a file/)