-
-
Notifications
You must be signed in to change notification settings - Fork 586
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.
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
Only a single change
event is fired for each file
#237
Comments
Version 0.11.* and below used polling on Linux by default, so setting Which editor are you using to modify your files? Very similar behavior used to exist when using vim because of its "atomic write" behavior. Perhaps you're using an editor that also does something similar, but following a different pattern than what has already been corrected for in chokidar. Also, if you add |
While trying to replicate this issue a moment ago I think I found where's the problem... I realized that I'm trying to monitor a symlink! Here's my require('chokidar').watch(process.argv[2])
.on("change", function(path) { console.log("CHANGE: " + path); })
.on("raw", console.log);
require('http').createServer().listen(8000); And here's my test: mkdir a
touch a/doc.txt
ln -s a b
gedit b/doc.txt &
node test.js b/doc.txt Now, I make some changes with
And that's it. Only the first change is detected, subsequent ones are completely ignored. Should symlinks be supported? |
Yes. I think Can you try with another editor like - like vim, emacs or sublime for instance. |
Actually it would also help if you watch the directory instead of the file directly. If you really only care about the one file you can use a glob pattern like |
I've just tried Actually, I've got here trying to solve my issue with |
Yep, polling will work, but it's not the preferable solution. When using |
Hello. Just to confirm this bug on ubuntu 14.04. Using JetBrains WebStorm (Java IDE). in mcedit everything works fine. |
A workaround not mentioned yet in this thread is to use a glob pattern which watches that one file, the effect of which is to force directory-level watching where the events sometimes land. So instead of watching Would appreciate feedback from anyone for whom this workaround does not work, as the fix in chokidar will likely apply a similar method. |
Thanks for the workaround. I was having this issue with Visual Studio 2013/15 on win 7, where I would only get the first change event. |
Let us know if that still happens with the latest chokidar. |
it does still happen with 1.6.0 (at least if gulp’s APIdocs are still right and it gulp 4.0 still uses chokidar behind the scenes) to fix it, we’d have to either
|
@flying-sheep: Run |
as said: 1.6.0: with
|
I'm also still seeing this issue with The workaround (ie. using glob patterns or polling) still works. Neither is ideal though. |
Using Ubuntu and Vim here, and I was able to workaround this by re-watching the file when it's renamed. It's also not ideal, but might be useful when avoiding dir-level handlers is desired. const startWatching = (watcher, file) => {
debug('Loading ' + file);
reloadFile(file)
.catch(console.error)
.then(() => {
watcher.unwatch(file);
watcher.add(file);
})
;
};
let calledOnce = false;
const watcher = chokidar.watch([], {persistent: true})
.on('change', reloadFile)
.on('raw', (type, filename, details) => {
// trigger only once on a rename, then wait for a moment to re-attach.
if( type === 'rename' && !calledOnce ) {
console.warn(filename + ' rename event caught. Avoid editing the file with an editor. Re-initializing chokidar watcher...');
calledOnce = true;
// wait for edits to be complete, then reload the file.
setTimeout(() => {
calledOnce = false;
startWatching(watcher, details.watchedPath);
}, 500);
}
})
;
startWatching(watcher, '/file'); |
Same issue here, with ubuntu 17.04 and parcel-bundler (which rely on chokidar for hot reloading). Switching to polling mode with Please open the issue again. |
@paulmillr @es128 Issue still happening in Manjaro (Arch) Linux using latest Neovim. Problem does not happen when globbing, however the advice given in #237 (comment) about wraping the first letter of file in square brackets leads to error from within chokidar's dependencies. Please re-open as of 09/2018 |
This is probably caused by On linux chokidar should probably listen for a rename event on the filename. As a proof of concept, save below script as const fs = require('fs')
const file = 'tmp.file.tmp'
let watcher
const watch = (file, rewatchOnRename) => {
try {
watcher = fs.watch(file, {
persistent: true
}, (e, f) => {
if (e === 'change') {
console.log('CHANGED')
} else if (rewatchOnRename && e === 'rename') {
watcher.close()
watch(file, rewatchOnRename)
}
})
} catch(e) {
if (e.code === 'ENOENT' && e.path === file) {
setTimeout(() => watch(file, rewatchOnRename), 1)
} else {
console.error(e)
}
}
}
function touch(file) {
if (fs.existsSync(file)) {
fs.unlinkSync(file)
}
fs.writeFileSync(file, '')
}
touch(file) // create the file
watch(file, !!process.argv[2])
setTimeout(() => touch(file), 1)
setTimeout(() => touch(file), 1000)
setTimeout(() => {
watcher.close()
fs.unlinkSync(file)
}, 2000) |
I tested this and I prefer solution with |
I think I fixed this in #791. |
See link for more info: paulmillr/chokidar#237 (comment)
See link for more info: paulmillr/chokidar#237 (comment)
Hello! @es128 Does not work for me on Windows with Git Bash: it never triggers using this trick. Here is the (original) script in
I tried the Before trying the I couldn't get the I am using the latest version of Then I tried to install the latest version ( Thanks for any input in this matter! Best, |
This should pull in this fix: paulmillr/chokidar#237
This is still present (chokidar 3.0.2) when using Ubuntu 19.04 in WSL on Windows 10 alongside neovim. Fairly esoteric use case I know but just thought I'd mention it as I saw this had been closed. The |
Encountered this on Debian 11, with chokidar 3.3.0, npm 6.13.1, and node 10.17.0. |
A code that reproduces this would be great. |
It's basically the same as the original example.
My first save to |
Which code editor do you use? |
Neovim 0.3.8; I tried Surprisingly, |
I'm having the same issue when using Vim and chokidar-cli. The first time the file is saved, the watch fires. Subsequent saves do nothing. The app is running in docker, with the app directory mounted. Setting polling to true works. |
Here on FreeBSD 12.1, using $ yarn list | grep chokidar
│ ├─ chokidar@^2.0.4
├─ chokidar@2.1.8
│ ├─ chokidar@^2.0.0 I believe Gulp's version is 2.1.8. |
You should update to chokidar 3. |
I see, didn't checked if chokidar had newer versions. Sorry. |
Just FYI: chokidar is working fine with neovim 0.4.3 chokidar 3.3.0, npm 6.13.1, and node 10.17.0, so I guess it's neovim that's misbehaving in my prior testing. |
in case someone still has it today : check if setTimeout works -.- in my case jsdom hooked setTimeout 🙈 and broke it |
Here's a very basic example:
After I run this code and start changing watched files I see the events being fired. The problem is that only the first change for each file is reported!
I have this issue with versions 0.12.* and 1.0.0-rc*. Versions 0.11.* and below seem to work fine.
I'm using Arch Linux with local Btrfs and Ext4 filesystems (tested both). Kernel: 3.18.6-1-ARCH, node: 0.10.36.
With
usePolling
option everything works fine.The text was updated successfully, but these errors were encountered: