question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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:

  • 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.

if(ts > startTime + FS_ACCURENCY) {

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:31
  • Comments:58 (5 by maintainers)

github_iconTop GitHub Comments

37reactions
yesskycommented, Mar 12, 2018

This issue also confused me for a while. finally I found a trick to fix it.

  const compiler = webpack(webpackConfig);
  const timefix = 11000;
  compiler.plugin('watch-run', (watching, callback) => {
    watching.startTime += timefix;
    callback()
  });
  compiler.plugin('done', (stats) => {
    stats.startTime -= timefix
  })

also a npm package is available https://github.com/yessky/webpack-mild-compile, it works with webpack v2/3/4.

21reactions
fenomascommented, Feb 26, 2018

For anyone else tearing out hair over this, backdating the relevant files by ten seconds is an awful hack but it worked for me:

var f = path.resolve('someFile')
var now = Date.now() / 1000
var then = now - 10
fs.utimes(f, then, then, function (err) { if (err) throw err })

Update - This fix stopped working for me at some point, but Yassky’s solution further down the page works great.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Loop a Video for Your Audience to Watch on Repeat
To loop your video, tap the “effects” button at the bottom left corner. Scroll through the options until you locate “time.” Select time...
Read more >
How to Loop Videos on iPhone? - Wondershare Filmora
These looping videos are fascinating and fun to watch. A loop is a popular element in photography and especially music videos, the idea...
Read more >
Open and play a file in QuickTime Player on Mac
Open the video or audio file you want to loop. · Choose View > Loop so a checkmark appears next to it. ·...
Read more >
3 Ways to Create Amazing Seamless Video Loops in ...
When you loop a complete project, the aim is to finish the video with the same frame as the start of the video....
Read more >
How to Loop a YouTube Video on Desktop and Mobile - InVideo
For quite some time, users resorted to various solutions, such as third-party tools, to play YouTube videos on repeat. It wasn't until YouTube ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found