onDidChange is called once
maximeallanic opened this issue · 9 comments
Replace fs.watch to fs.watchFile in _watch method.
It indeed is called once, and fs.watchFile works as expected as @maximeallanic said, so,is there any plan to fix the issue? @sindresorhus
What Node.js version and operating system?
fs.watch
was an intentional choice. If it doesn't work, I recommend opening an issue on Node.js instead.
From the Node.js docs:
Using fs.watch() is more efficient than fs.watchFile and fs.unwatchFile. fs.watch should be used instead of fs.watchFile and fs.unwatchFile when possible.
// @yaodingyd
Have the same issue. the onDidChange is only called the first time I change the file config file.
Node v12.16.3 and Fedora 32
MacOS 10.15.5 and Node 12.6.3
I can't reproduce this on my machine. macOS: 10.14.6 node: 12.4.0
Windows 10:
- node: 12.18.3
- fs.watch - Ok
- fs.watchFile - Ok (+- 1s delay)
Ubuntu 20.04:
- node 12.18.3
- fs.watch - Fail (once)
- fs.watchFile - Ok
Mac:
- I don't have = (
as said by @sindresorhus seems to be a nodejs problem.
There are several issues about this case such as:
- nodejs/node#5039
- nodejs/node#22517
and several others that despite being closed, problem continues to occur.
I suggest two workarounds:
- Implementation of https://github.com/paulmillr/chokidar
- Add { watchFile: true | false } like { watch: true | false }
@adlerluiz Can you check the latest Node.js 15 version? Would be useful to see if that improves the situation. (We'll still need to work around for Node.js 12)