--watch restarts only once
Version
v20.15.1
Platform
Linux derby 6.6.46-0-lts #1-Alpine SMP PREEMPT_DYNAMIC 2024-08-16 08:05:54 x86_64 Linux
Subsystem
No response
What steps will reproduce the bug?
f.js contains only console.log('hello')
node --watch f.js
hello
Completed running 'f.js'
Change f.js to console.log('hello world')
Restarting 'f.js'
hello world
Completed running 'f.js'
Change f.js again, e.g. console.log('this change will not restart watcher')
No change in the watch output.
(I'm changing the file outside of the debounce/throttle period)
How often does it reproduce? Is there a required condition?
It happens every time.
What is the expected behavior? Why is that the expected behavior?
I would expect that --watch would restart after every write to f.js, not just after the first change made to the file.
What do you see instead?
--watch only seems to restart after making the first change to the file.
Additional information
Also seeing this problem on Termux for Android node v22.5.1
I can't reproduce on v22.8.0, nor can I in v20.17.0:
console.log('Unmodified Data');
I changed the value of the
console.logfor this example.
$ node --watch repro.js
Unmodified Data
Completed running 'repro.js'
Restarting 'repro.js'
Modified Data (!)
Completed running 'repro.js'
Restarting 'repro.js'
Modified Data (!!)
Completed running 'repro.js'
This output has been modified, stripping the control characters.
Can you provide more information?
I'll get a binary for one of those versions you listed and try it again tomorrow.
Also seeing this on v21.7.3 Could it be a filesystem issue? I'm using ext4 on a pretty fresh install of Alpine.
Please attempt to reproduce on the latest version of v20 or v22.
I'm having trouble getting the prebuilt binaries to run (the only output I get is "cannot execute: required file not found"). Also, using nvm fails when it attempts to build from source because alpine uses musl instead of glibc. Are you able to reproduce the issue on v20.15.1 or v21.7.3 or v22.5.1 ? If so, I think we can assume it's fixed in those later versions, and we can close this issue.
I haven't attempted to reproduce on those versions–but considering that they aren't reproducible on the latest version. I'm closing this issue.
If you manage to reproduce, feel free to reopen.
Also happens with the official node docker image on linux.
FROM node:23
...
ENTRYPOINT ["node", "--watch", "server.js"]
It also restarts only once on v22.13.1. I have installed it via nvm on a debian12.
This is happening to me on v22.15.0 installed with nvm. Also on Debian 12
This also happens on WSL2 Debian 12 installation.
➜ ~ git:(master) ✗ uname -a
Linux JLCEast 5.15.167.4-microsoft-standard-WSL2 #1 SMP Tue Nov 5 00:21:55 UTC 2024 x86_64 GNU/Linux
➜ ~ git:(master) ✗ node -v
v23.11.0
also on WSL2 NixOS
› uname -a
Linux nixos 6.6.87.2-microsoft-standard-WSL2 #1 SMP PREEMPT_DYNAMIC Thu Jun 5 18:30:46 UTC 2025 x86_64 GNU/Linux
› node -v
v24.5.0
--watch-path seems to work as you would expect.
Same behavior for docker image: node:lts-alpine
mac os 15.5
I encountered the same issue with both node 22.18.0 and 24.5.0 while editing files with neovim (0.11) on linux.
If I understand correctly, when writing a file, neovim creates a backup of the original file, then writes the new content.
By default, neovim renames the original file, and creates a new file in place of the original file. On the first edit, node --watch correctly restarts the process. However, subsequent edits are not picked up by node --watch.
A workaround is to change the neovim option backupcopy to yes. If set to yes, instead of renaming the original file to create a backup, then creating a new file in place of the original, neovim will make a copy of the original file and will then overwrite the original file. In that case, node --watch works fine.