GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — watch: remove NODE_OPTIONS from spawn call to prevent infinite loop by viiktordev · Pull Request #61838 · nodejs/node

watch: remove NODE_OPTIONS from spawn call to prevent infinite loop #61838

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
viiktordev wants to merge 3 commits into nodejs:main from viiktordev:fix/watch-options-infinite-loop

Uh oh!

There was an error while loading. Please reload this page.

Closed

watch: remove NODE_OPTIONS from spawn call to prevent infinite loop #61838

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
3 commits
Select commit Hold shift + click to select a range
e9e40d5
watch: remove NODE_OPTIONS from spawn call to prevent infinite loop
viiktordev Feb 14, 2026
8ed076a
watch: fix lint
viiktordev Feb 15, 2026
29cb7d6
Merge branch 'main' into fix/watch-options-infinite-loop
viiktordev Feb 15, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

11 changes: 7 additions & 4 deletions 11 lib/internal/main/watch_mode.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,15 @@ let exited;
function start() {
exited = false;
const stdio = kShouldFilterModules ? ['inherit', 'inherit', 'inherit', 'ipc'] : 'inherit';
const env = {
...process.env,
WATCH_REPORT_DEPENDENCIES: '1',
};

delete env.NODE_OPTIONS;
child = spawn(process.execPath, argsWithoutWatchOptions, {
stdio,
env: {
...process.env,
WATCH_REPORT_DEPENDENCIES: '1',
},
env,
});
watcher.watchChildProcessModules(child);
if (kEnvFiles.length > 0) {
Expand Down
73 changes: 72 additions & 1 deletion 73 test/sequential/test-watch-mode-watch-flags.mjs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import path from 'node:path';
import { execPath } from 'node:process';
import { describe, it } from 'node:test';
import { spawn } from 'node:child_process';
import { writeFileSync, mkdirSync } from 'node:fs';
import { writeFileSync, mkdirSync, chmodSync } from 'node:fs';
import { inspect } from 'node:util';
import { createInterface } from 'node:readline';

Expand Down Expand Up @@ -48,6 +48,44 @@ async function runNode({
return { stdout, stderr, pid: child.pid };
}

async function runExecutable({
file,
expectedCompletionLog = 'Completed running',
options = {},
timeout = common.platformTimeout(10_000),
}) {
const child = spawn(file, [], { encoding: 'utf8', stdio: 'pipe', ...options });
let stderr = '';
const stdout = [];
let timedOut = true;

child.stderr.on('data', (data) => {
stderr += data;
});

const timer = setTimeout(() => {
child.kill();
}, timeout);

try {
for await (const data of createInterface({ input: child.stdout })) {
if (!data.startsWith('Waiting for graceful termination') &&
!data.startsWith('Gracefully restarted')) {
stdout.push(data);
}
if (data.startsWith(expectedCompletionLog)) {
timedOut = false;
break;
}
}
} finally {
clearTimeout(timer);
child.kill();
}

return { stdout, stderr, timedOut };
}

tmpdir.refresh();

describe('watch mode - watch flags', { concurrency: !process.env.TEST_PARALLEL, timeout: 60_000 }, () => {
Expand Down Expand Up @@ -94,4 +132,37 @@ describe('watch mode - watch flags', { concurrency: !process.env.TEST_PARALLEL,
`Completed running ${inspect(file)}. Waiting for file changes before restarting...`,
]);
});

it('should not recursively re-enter watch mode for shebang scripts when NODE_OPTIONS=--watch',
{ skip: common.isWindows || process.config.variables.node_without_node_options },
async () => {
const projectDir = tmpdir.resolve('project-watch-node-options-shebang');
mkdirSync(projectDir);

const file = createTmpFile(
'#!/usr/bin/env node\nconsole.log("shebang run");\n',
'.js',
projectDir,
);
chmodSync(file, 0o755);

const { stdout, stderr, timedOut } = await runExecutable({
file,
options: {
cwd: projectDir,
env: {
...process.env,
NODE_OPTIONS: '--watch',
PATH: `${path.dirname(execPath)}${path.delimiter}${process.env.PATH ?? ''}`,
},
},
});

assert.strictEqual(timedOut, false);
assert.strictEqual(stderr, '');
assert.deepStrictEqual(stdout, [
'shebang run',
`Completed running ${inspect(file)}. Waiting for file changes before restarting...`,
]);
});
});
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.