You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Files created right before watching starts make watching go into a loop #25
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:
compilation succeeds
Watching.prototype._done gets called
recalling Watching.prototype.watch
which immediately triggers a change event for the /temp/entry.js file, because it's < 10 seconds old
back to step 1
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.
FS_ACCURENCY should automatically adjust to your file system accuracy. This may not happen fast enough if you have few files and the files are created unlucky on a timestamp modulo 10s.
The watching may loop in a unlucky case, but this should not result in a different compilation hash. I. e. the webpack-dev-server doesn't trigger a update if the hash is equal.
Ah, but Im experiencing this issue 100% of the time, because I am
programatically creating the entry.js file and starting the watch process
on it right away. So for 10s it keeps rebuilding continuously.
On Fri, 6 May 2016 at 13:12, Tobias Koppers notifications@github.com
wrote:
The watching may loop in a unlucky case, but this should not result in a
different compilation hash. I. e. the webpack-dev-server doesn't trigger a
update if the hash is equal.
—
You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub #25 (comment)
Would be nice to resolve this without having to fork webpack or delay
watching for 10s. I wonder if I could create a file with an older
timestamp..
On Fri, 6 May 2016 at 18:29, Karolis Narkevičius karolis.n@gmail.com
wrote:
Ah, but Im experiencing this issue 100% of the time, because I am
programatically creating the entry.js file and starting the watch process
on it right away. So for 10s it keeps rebuilding continuously.
On Fri, 6 May 2016 at 13:12, Tobias Koppers notifications@github.com
wrote:
The watching may loop in a unlucky case, but this should not result in a
different compilation hash. I. e. the webpack-dev-server doesn't trigger a
update if the hash is equal.
—
You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub #25 (comment)
Reacted by Felipe C, Brian Frichette, Alexandre Galays and Raymond May Jr.
@sokra "FS_ACCURENCY" only adjusts itself when you get an actual onChange event. When you first fire compiler.watch(), and the compilation is fast enough (say, one file with no bundled dependencies), assuming you saved the file in the last few seconds, watchpack will keep emitting change events until the difference gets large enough.
When chokidar is using fswatch (OSX), FS_ACCURENCY eventually settles on 2000 if you trigger some real change events (not sure why, fsevent timestamps are multiples of 1000).
Maybe FS_ACCURENCY should get a first adjustment on the nextTick handler; at least that would reduce the worst case to 2s as opposed to 10s. If the build is really fast (say, ~400ms per build), you can easily get 20+ rebuilds at the start if you touched any file before starting the watch process.
It'd also be nice if it got renamed to FS_PRECISION, but that's going off-topic :)
We are having the same problem. A workaround we found is to manually change the mtime of the file before it gets picked up by Webpack, but it feels like just adding a hack on top of a hack.
Reacted by Felipe C, Kees Kluskens, Brian Frichette and Greg Connell
This problem has been haunting our team for a while. Files are being stored on doInitialScan() 10 seconds in the future and this generates multiple webpack-dev-middleware builds until the future becomes the past. It seems to me that watchpack should compare mtimes between nextTick()s instead of trying to guess if the mtime is in the future or in the past.
Watchpacks strategy is: if not sure if it's a change, thread it as change. With low fs accuracy files could have changed even if mime is equal.
Normally multiple rebuilds shouldn't cause issues and this cause should be cached by the caller by comparing hash. I.e. the webpack CLI doesn't display stats output for equal hash.
Nevertheless this may could be fixed in watch pack by storing the time of the initial scan/watcher installation and useing this time.
How is FS_ACCURENCY helping in that case? If the filesystem doesn't provide the precision necessary to detect the change, FS_ACCURENCY will only add X milliseconds to that lack of precision. If mtime didn't change because of lack of precision, adding FS_ACCURENCY to it won't make it any different. The only reason I can imagine is when trying to guess if the mtime is in the future or not, and what I propose is to stop doing that and just act upon the change in mtime itself.
FYI, here's an extract of what we see if we have a recent change before starting webpack-dev-middleware. I put a loop printing the current date in the background and added some console.logs for debugging purposes showing arguments for the compiler plugins. Note that the hash remains the same and the multiple builds happening until startTime is greater than mtime + FS_ACCURENCY:
We are experiencing the endless rebuilding problem even for files that weren't created shortly before watching started. This is a problem that has affected us with Webpack 1 as well as 2, and occurs sporadically but often enough that it makes working with webpack-dev-server a chore and it almost makes one long for the days of grunt-watch and BrowserSync. ;) Here is a link to our config: https://gist.github.com/mischkl/cf7ab4b10df9763aa698a5b885f700cd
This is on Windows 7 Enterprise x64 with Node 6.9.1, and seems to primarily happen when IntelliJ IDEA is open.
I should also note that we have seen the problem when using angular-cli with the default settings as well. The fact that it only seems to affect a subset of users makes me strongly suspect that this is a Windows/Intellij/WebStorm-related issue.
Update - This fix stopped working for me at some point, but Yassky's solution further down the page works great.
Reacted by Sébastien Chopin, EGOIST, jxkolesnikov, hoperyy, Daniel O’Connor, calledt, var-bp, Gabo Lugo, タピオカ飲んでTikTokやってSNSでいいねもらえたら後はどうでもいい, Michael Calkins and 11 more
Watchpacks strategy is: if not sure if it's a change, thread it as change. With low fs accuracy files could have changed even if mime is equal.
Normally multiple rebuilds shouldn't cause issues and this cause should be cached by the caller by comparing hash. I.e. the webpack CLI doesn't display stats output for equal hash.
Nevertheless this may could be fixed in watch pack by storing the time of the initial scan/watcher installation and useing this time.
I am looking forward to the official solution to this problem.
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
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 webpack/webpack#7997 by @jods4. By changing the mtime of the file in the invalid sync hook, the loop seems to be prevented.
Edit for context:
I'm generating my watched file first in the environment hook to catch the initial compile and non-watch related compiles
I then rerun the generation scripts in the invalid hook
I then update the mtime in the invalid hook immediately after
plugins: [
{
apply: (compiler) => {
compiler.hooks.environment.tap('environment', () => {
// ... Manipulate watched file
})
compiler.hooks.invalid.tap('invalid', (fileName, changeTime) => {
// ... Manipulate watched file again
// Update the mtime
var my_manipulated_file = path.resolve('path/to/my/manipulated/file')
var now = Date.now() / 1000
var then = now - 100
fs.utimes(my_manipulated_file, then, then, function (err) { if (err) throw err })
},
},
]
Activity
sokra commentedon May 6, 2016
FS_ACCURENCYshould automatically adjust to your file system accuracy. This may not happen fast enough if you have few files and the files are created unlucky on a timestamp modulo 10s.The watching may loop in a unlucky case, but this should not result in a different compilation hash. I. e. the webpack-dev-server doesn't trigger a update if the hash is equal.
KidkArolis commentedon May 6, 2016
Ah, but Im experiencing this issue 100% of the time, because I am
programatically creating the entry.js file and starting the watch process
on it right away. So for 10s it keeps rebuilding continuously.
On Fri, 6 May 2016 at 13:12, Tobias Koppers notifications@github.com
wrote:
KidkArolis commentedon May 6, 2016
Would be nice to resolve this without having to fork webpack or delay
watching for 10s. I wonder if I could create a file with an older
timestamp..
On Fri, 6 May 2016 at 18:29, Karolis Narkevičius karolis.n@gmail.com
wrote:
Jessidhia commentedon Jul 14, 2016
@sokra "
FS_ACCURENCY" only adjusts itself when you get an actualonChangeevent. When you first firecompiler.watch(), and the compilation is fast enough (say, one file with no bundled dependencies), assuming you saved the file in the last few seconds, watchpack will keep emittingchangeevents until the difference gets large enough.When chokidar is using fswatch (OSX),
FS_ACCURENCYeventually settles on2000if you trigger some real change events (not sure why,fseventtimestamps are multiples of1000).Maybe
FS_ACCURENCYshould get a first adjustment on thenextTickhandler; at least that would reduce the worst case to 2s as opposed to 10s. If the build is really fast (say, ~400ms per build), you can easily get 20+ rebuilds at the start if you touched any file before starting the watch process.It'd also be nice if it got renamed to
FS_PRECISION, but that's going off-topic :)rochdev commentedon Oct 18, 2016
We are having the same problem. A workaround we found is to manually change the mtime of the file before it gets picked up by Webpack, but it feels like just adding a hack on top of a hack.
hrimhari commentedon Oct 18, 2016
This problem has been haunting our team for a while. Files are being stored on doInitialScan() 10 seconds in the future and this generates multiple webpack-dev-middleware builds until the future becomes the past. It seems to me that watchpack should compare mtimes between nextTick()s instead of trying to guess if the mtime is in the future or in the past.
sokra commentedon Oct 19, 2016
Watchpacks strategy is: if not sure if it's a change, thread it as change. With low fs accuracy files could have changed even if mime is equal.
Normally multiple rebuilds shouldn't cause issues and this cause should be cached by the caller by comparing hash. I.e. the webpack CLI doesn't display stats output for equal hash.
Nevertheless this may could be fixed in watch pack by storing the time of the initial scan/watcher installation and useing this time.
hrimhari commentedon Oct 19, 2016
How is FS_ACCURENCY helping in that case? If the filesystem doesn't provide the precision necessary to detect the change, FS_ACCURENCY will only add X milliseconds to that lack of precision. If mtime didn't change because of lack of precision, adding FS_ACCURENCY to it won't make it any different. The only reason I can imagine is when trying to guess if the mtime is in the future or not, and what I propose is to stop doing that and just act upon the change in mtime itself.
hrimhari commentedon Oct 19, 2016
FYI, here's an extract of what we see if we have a recent change before starting webpack-dev-middleware. I put a loop printing the current date in the background and added some console.logs for debugging purposes showing
argumentsfor the compiler plugins. Note that the hash remains the same and the multiple builds happening untilstartTimeis greater thanmtime+FS_ACCURENCY:mischkl commentedon Nov 22, 2016
We are experiencing the endless rebuilding problem even for files that weren't created shortly before watching started. This is a problem that has affected us with Webpack 1 as well as 2, and occurs sporadically but often enough that it makes working with webpack-dev-server a chore and it almost makes one long for the days of grunt-watch and BrowserSync. ;) Here is a link to our config:
https://gist.github.com/mischkl/cf7ab4b10df9763aa698a5b885f700cd
This is on Windows 7 Enterprise x64 with Node 6.9.1, and seems to primarily happen when IntelliJ IDEA is open.
I should also note that we have seen the problem when using
angular-cliwith the default settings as well. The fact that it only seems to affect a subset of users makes me strongly suspect that this is a Windows/Intellij/WebStorm-related issue.fenomas commentedon Mar 20, 2017
For anyone else tearing out hair over this, backdating the relevant files by ten seconds is an awful hack but it worked for me:
Update - This fix stopped working for me at some point, but Yassky's solution further down the page works great.
atinux commentedon Mar 25, 2017
You just made my day @AndyHall
I confirm that his solution works like a charm!
fix(watch): Add workaround for the webpack watch issue
multiple watches on start is out of my hands has to do with webpack/w…
trsh commentedon Jul 25, 2017
Same here, check #53. My explanation why this happens is very detailed.
43 remaining items
yuchonghua commentedon Jan 6, 2019
I am looking forward to the official solution to this problem.
fix($core): know issue: webpack/watchpack#25
sokra commentedon Jul 10, 2019
old issue
problem is kind of expected behavior
we reduced the startup filesystem accuracy to 1 second which should reduce the problem
hrimhari commentedon Jul 10, 2019
Given the number of people complaining, "expected behavior" seems inappropriate as a classification.
Why not just get rid of FS_ACCURACY?
cliedelt commentedon Jul 19, 2019
I still have this issue and this cannot be the expected behavior...
turnerhayes commentedon May 30, 2020
I'm having this issue too and the suggested workarounds don't work. Can you reopen this?
imagina commentedon Nov 27, 2020
Same issue here. The only fix for me was to add the plugin: https://github.com/yessky/webpack-mild-compile
afazzdev commentedon Jun 25, 2021
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 commentedon Jul 5, 2021
hedonicadapter commentedon Sep 2, 2021
having this issue right now, the solutions don't seem to work (that is if I'm doing them correctly)
bardsol commentedon Dec 1, 2021
Having the same issue with webpack 5
JoshBeveridge commentedon Jul 27, 2022
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 webpack/webpack#7997 by @jods4. By changing the
mtimeof the file in theinvalidsync hook, the loop seems to be prevented.Edit for context:
environmenthook to catch the initial compile and non-watch related compilesinvalidhookmtimein theinvalidhook immediately afterdashcode commentedon Aug 29, 2023
Hi. Lost a workday because of this. Please, consider fixing it. Thanks.
oshilaRightS commentedon Sep 7, 2023
Its again happening in Angular 16 related. Kindly fix this permanently. thank you.