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.

Wrong gulp example?

See original GitHub issue

I’ve integrated browser-sync in my gulp tool chain like this: http://www.browsersync.io/docs/gulp/#gulp-reload. The part I’m questioning is this one:

// create a task that ensures the `js` task is complete before
// reloading browsers
gulp.task('js-watch', ['js'], browserSync.reload);

Basically gulp is watching the js-directory and this ‘js-watch’ should be called every time a change is detected.

The problem I’ve experienced is, that this task never ends, looks like browserSync.reload never returns anything (in the command line i never see any ‘finished js-watch’ information) and the browser therefore reloads only once. Every change after the first one, won’t result in any browser reload, as the ‘js-watch’-task is still running.

The following code fixed this for me:

gulp.task('js-watch', ['scripts'], function(){
    browserSync.reload();
    return;
});

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:13 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
haluvibecommented, Jul 7, 2016

Igladdy is 100% correct! This example worked for me. Note: Using Gulp 4

function reload(done) {
  browserSync.reload();
  done();
}

gulp.watch('src/styles/*.css', gulp.series(postCss, reload));

3reactions
lgladdycommented, Jun 7, 2016

For what it’s worth, I came here after having this issue, but it wasn’t related to an anonymous function.

It was due to a change in how gulp processes watch tasks, which was way over my head, but explained in https://github.com/gulpjs/gulp/issues/1623 and https://github.com/gulpjs/gulp/issues/1624

An example of how to handle the done function properly is in this merge request that fixes the issue for Zurb Foundation: https://github.com/zurb/foundation-zurb-template/pull/37/files

Read more comments on GitHub >

github_iconTop Results From Across the Web

Gulp error: The following tasks did not complete - Stack Overflow
I've seen a few example Gulp 4 examples such as this one where watchers don't seem to be accompanied by completion signals. What...
Read more >
Error management in gulp - gists · GitHub
Suppose you have a task in gulpfile. js that contains this code (we modified it a little bit to be closer to real-usage):...
Read more >
My gulp clean task throwing me an error (Example) - Treehouse
Hi, I have a problem when i run the gulp clean task. tree... ... Error: Cannot find module 'gulp-sourcemaps' at Function.Module.
Read more >
Getting Started with Gulp.js - Semaphore Tutorial
In this example, we capture the error event with .on('error') and call the callback with an Error instance. With return we ensure that...
Read more >
Gulp for Beginners | CSS-Tricks
Gulp is a tool that helps you out with several tasks when it comes to web development. It's often used to do front...
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