webpack / watchpack

Wrapper library for directory and file watching.
MIT License
377 stars 106 forks source link

Files created right before watching starts make watching go into a loop #25

Closed KidkArolis closed 5 years ago

KidkArolis commented 8 years ago

I've noticed this strange behaviour where watcher loops for 10 seconds due to this code:

if(data) {
  var ts = data[0] === data[1] ? data[0] + FS_ACCURENCY : data[0];
  if(ts > startTime)
    watcher.emit("change", data[1] + FS_ACCURENCY);
}

https://github.com/webpack/watchpack/blob/7efdd93aff0c991a766af886ccc16324401a202f/lib/DirectoryWatcher.js#L202-L205

What I'm doing in my script is basically creating a file in a temporary directory /temp/entry.js, creating a webpack compiler and run compiler.watch(). Now for 10 seconds (which is the default value of FS_ACCURENCY) this is what's happening:

Any pointers on how to fix this would be helpful. For example, this could be fixed by modifying the above code to this, but I'd need to stare at this for longer to understand what this block of code is conceptually responsible for.

if(ts > startTime + FS_ACCURENCY) {
cliedelt commented 5 years ago

I still have this issue and this cannot be the expected behavior...

turnerhayes commented 4 years ago

I'm having this issue too and the suggested workarounds don't work. Can you reopen this?

imagina commented 3 years ago

Same issue here. The only fix for me was to add the plugin: https://github.com/yessky/webpack-mild-compile

afazzdev commented 3 years ago

i'm experiencing this bug, but with webpack 5. i've try using webpack-mild-compile but no hope. any idea how to resolve this issue?

yessky commented 3 years ago

i'm experiencing this bug, but with webpack 5. i've try using webpack-mild-compile but no hope. any idea how to resolve this issue? Could you provide reproduceable demo project? I'd try to fix it recently Try webpack-mild-compile@3.4.0

hedonicadapter commented 3 years ago

having this issue right now, the solutions don't seem to work (that is if I'm doing them correctly)

bardsol commented 2 years ago

Having the same issue with webpack 5

JoshBeveridge commented 2 years ago

Popping in here to say that I have a similar problem because I need to manipulate a file Webpack is watching before the watch compile occurs. The only solution that has worked for me is to combine the solution proposed by @fenomas with the information I found in https://github.com/webpack/webpack/issues/7997 by @jods4. By changing the mtime of the file in the invalid sync hook, the loop seems to be prevented.

Edit for context:

dashcode commented 1 year ago

Hi. Lost a workday because of this. Please, consider fixing it. Thanks.

oshilaRightS commented 1 year ago

Its again happening in Angular 16 related. Kindly fix this permanently. thank you.