Sitelet https://github.com/nodejs/node/issues/55913
Skip to content

--watch-path also watches --env file directory tree in >=22.7 #55913

Description

@gorankarlic

Version

22.7.0

Platform

Darwin Users-MacBook-Air-2.local 24.0.0 Darwin Kernel Version 24.0.0: Tue Sep 24 23:37:13 PDT 2024; root:xnu-11215.1.12~1/RELEASE_ARM64_T8112 arm64

Subsystem

No response

What steps will reproduce the bug?

When running node --watch-path lib test.js with 22.6.0 it behaves as expected (restarts only when a file changes in the lib directory).

When running node --watch-path lib test.js with 22.7.0 it keeps restarting indefinitely.

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

Always reproducible.

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

Should only restart when a file changes in the watched directory.

What do you see instead?

Restarting indefinitely in a loop.

Additional information

No response

Activity

  1. targos commented on Nov 19, 2024

    @targos
    Member

    I'm not able to reproduce.

  2. gorankarlic commented on Nov 20, 2024

    @gorankarlic
    Author

    I have discovered that the issue is a bit more convoluted and indeed can not be reproduced as stated above.

    In order to reproduce the issue two conditions must be met:

    1. --env argument must be present
    2. --watch-path argument must be present

    --watch-preserve-output is used here only for easier observation but is not required to reproduce the issue

    node --env-file sub/dev.env --watch-path /usr/local/bin --watch-preserve-output index.js

    In this case Node 22.7 and above erroneously starts watching the directory tree where the environment file (in this casedev.env) is located. That means that executing touch sub/test.txt triggers a restart.

    Please find attached a complete example 55913.zip that can be used with the above description to reliably reproduce the issue.

  3. pmarchini commented on Nov 20, 2024

    @pmarchini
    Member

    Hey @gorankarlic, could you please provide the repro as a public repository? 😊

  4. gorankarlic commented on Nov 21, 2024

    @gorankarlic
    Author

    Hey @gorankarlic, could you please provide the repro as a public repository? 😊

    Please find the public repository with the reproducible at https://github.com/gorankarlic/55913.

  5. pmarchini commented on Nov 21, 2024

    @pmarchini
    Member

    Hey @gorankarlic, could you please provide the repro as a public repository? 😊

    Please find the public repository with the reproducible at https://github.com/gorankarlic/55913.

    Thanks @gorankarlic 😊

  6. changed the title [-]`--watch-path` broken starting with version 22.7[/-] [+]`--watch-path` also watches `--env` file directory tree in >=22.7[/+] on Nov 21, 2024
  7. gorankarlic commented on Nov 26, 2024

    @gorankarlic
    Author

    It seems that the pull request #54109 that was merged into 22.7 introduced this issue, i.e. instead of watching just the env file it watches the directory tree where the env file is located. @marekpiechut any ideas how it could be fixed?

  8. added a commit that references this issue on Dec 1, 2024
  9. added a commit that references this issue on Jan 16, 2025
  10. github-actions commented on Apr 26, 2026

    @github-actions
    Contributor

    This issue has been marked as stale due to 210 days of inactivity.
    It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.

  11. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Apr 26, 2026
  12. github-actions commented on May 26, 2026

    @github-actions
    Contributor

    This issue has been automatically closed after 30 days of inactivity following its stale status (no activity for a total of 240 days).
    If this is still relevant, feel free to reopen it or leave a comment with additional details so we can continue the discussion.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions