Skip to content

--watch combined with --watch-path results in duplicate restart events/logs #57124

@OliverJAsh

Description

@OliverJAsh

Version

22.13.1

Platform

Darwin macbookpro.lan 24.3.0 Darwin Kernel Version 24.3.0: Thu Jan  2 20:24:16 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T6000 arm64 arm Darwin

Subsystem

No response

What steps will reproduce the bug?

Full reduced test case: https://github.com/OliverJAsh/node-watch-bug

src/server.js:

setTimeout(() => {}, 100000);
  1. Run node --watch --watch-path=./src/ ./src/server.js
  2. In another terminal run touch ./src/server.js.

How often does it reproduce? Is there a required condition?

Every time.

What is the expected behavior? Why is that the expected behavior?

1 restart event/log:

Restarting './src/server.js'

This is what we get when we remove --watch and only specify --watch-path:

$ node --watch-path=./src/ ./src/server.js
Restarting './src/server.js'

Curiously, this is also the behaviour we get if we add --watch-preserve-output:

$ node --watch --watch-preserve-output --watch-path=./src/ ./src/server.js
Restarting './src/server.js'

What do you see instead?

2 restart events/logs:

$ node --watch --watch-path=./src/ ./src/server.js
Restarting './src/server.js'
Restarting './src/server.js'

Additional information

This part of the docs seems relevant:

This will turn off watching of required or imported modules, even when used in combination with --watch.

https://nodejs.org/docs/latest-v22.x/api/cli.html#--watch-path

Potentially related: #55189

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions