Gulp v4 watch task





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0

















I just upgraded to Gulp v4 and was wondering why my gulpfile isn't working anymore.

I tried the new code of the new documentation but it didn't worked out as planned because I'm using "pure" postcss.

So I googled for my issue and found this question: Gulp error: watch task has to be a function

However, this also wasnt a solution for my problem, although I get the same error message Error: watching src/styles/**/*.scss: watch task has to be a function


I currently have this code



var gulp = require('gulp');
var sass = require('gulp-sass');
var postcss = require('gulp-postcss');
var autoprefixer = require('autoprefixer');
var cssnano = require('cssnano');

gulp.task('default', function () {
gulp.watch('src/styles/**/*.scss', ['styles']);
});

gulp.task('styles', function () {
var processors = [
autoprefixer({
browsers: ['last 3 versions', 'ie > 9']
}),
cssnano()
];
gulp.src('src/styles/main.scss')
.pipe(sass().on('error', sass.logError))
.pipe(postcss(processors))
.pipe(gulp.dest('dist/files/styles/'));
});


and when I change
gulp.watch('src/styles/**/*.scss', ['styles']);

to
gulp.watch('src/styles/**/*.scss', gulp.series('styles'));

it just gives me a Starting 'default'... and after changing a file Starting 'styles'...

with Gulp 3.9 it was



Starting 'default'...
Finished 'default' after 174 ms


and after changing a file



Starting 'styles'...
Finished 'styles' after 561 μs


I've now tried many different things but I just dont get it to work like it did before. I'm really thinking of switching over to webpack like the cool kids now. But Gulp always worked fine.


Can someone explain to me what I'm doing wrong?










share|improve this question





























    0

















    I just upgraded to Gulp v4 and was wondering why my gulpfile isn't working anymore.

    I tried the new code of the new documentation but it didn't worked out as planned because I'm using "pure" postcss.

    So I googled for my issue and found this question: Gulp error: watch task has to be a function

    However, this also wasnt a solution for my problem, although I get the same error message Error: watching src/styles/**/*.scss: watch task has to be a function


    I currently have this code



    var gulp = require('gulp');
    var sass = require('gulp-sass');
    var postcss = require('gulp-postcss');
    var autoprefixer = require('autoprefixer');
    var cssnano = require('cssnano');

    gulp.task('default', function () {
    gulp.watch('src/styles/**/*.scss', ['styles']);
    });

    gulp.task('styles', function () {
    var processors = [
    autoprefixer({
    browsers: ['last 3 versions', 'ie > 9']
    }),
    cssnano()
    ];
    gulp.src('src/styles/main.scss')
    .pipe(sass().on('error', sass.logError))
    .pipe(postcss(processors))
    .pipe(gulp.dest('dist/files/styles/'));
    });


    and when I change
    gulp.watch('src/styles/**/*.scss', ['styles']);

    to
    gulp.watch('src/styles/**/*.scss', gulp.series('styles'));

    it just gives me a Starting 'default'... and after changing a file Starting 'styles'...

    with Gulp 3.9 it was



    Starting 'default'...
    Finished 'default' after 174 ms


    and after changing a file



    Starting 'styles'...
    Finished 'styles' after 561 μs


    I've now tried many different things but I just dont get it to work like it did before. I'm really thinking of switching over to webpack like the cool kids now. But Gulp always worked fine.


    Can someone explain to me what I'm doing wrong?










    share|improve this question

























      0












      0








      0










      I just upgraded to Gulp v4 and was wondering why my gulpfile isn't working anymore.

      I tried the new code of the new documentation but it didn't worked out as planned because I'm using "pure" postcss.

      So I googled for my issue and found this question: Gulp error: watch task has to be a function

      However, this also wasnt a solution for my problem, although I get the same error message Error: watching src/styles/**/*.scss: watch task has to be a function


      I currently have this code



      var gulp = require('gulp');
      var sass = require('gulp-sass');
      var postcss = require('gulp-postcss');
      var autoprefixer = require('autoprefixer');
      var cssnano = require('cssnano');

      gulp.task('default', function () {
      gulp.watch('src/styles/**/*.scss', ['styles']);
      });

      gulp.task('styles', function () {
      var processors = [
      autoprefixer({
      browsers: ['last 3 versions', 'ie > 9']
      }),
      cssnano()
      ];
      gulp.src('src/styles/main.scss')
      .pipe(sass().on('error', sass.logError))
      .pipe(postcss(processors))
      .pipe(gulp.dest('dist/files/styles/'));
      });


      and when I change
      gulp.watch('src/styles/**/*.scss', ['styles']);

      to
      gulp.watch('src/styles/**/*.scss', gulp.series('styles'));

      it just gives me a Starting 'default'... and after changing a file Starting 'styles'...

      with Gulp 3.9 it was



      Starting 'default'...
      Finished 'default' after 174 ms


      and after changing a file



      Starting 'styles'...
      Finished 'styles' after 561 μs


      I've now tried many different things but I just dont get it to work like it did before. I'm really thinking of switching over to webpack like the cool kids now. But Gulp always worked fine.


      Can someone explain to me what I'm doing wrong?










      share|improve this question
















      I just upgraded to Gulp v4 and was wondering why my gulpfile isn't working anymore.

      I tried the new code of the new documentation but it didn't worked out as planned because I'm using "pure" postcss.

      So I googled for my issue and found this question: Gulp error: watch task has to be a function

      However, this also wasnt a solution for my problem, although I get the same error message Error: watching src/styles/**/*.scss: watch task has to be a function


      I currently have this code



      var gulp = require('gulp');
      var sass = require('gulp-sass');
      var postcss = require('gulp-postcss');
      var autoprefixer = require('autoprefixer');
      var cssnano = require('cssnano');

      gulp.task('default', function () {
      gulp.watch('src/styles/**/*.scss', ['styles']);
      });

      gulp.task('styles', function () {
      var processors = [
      autoprefixer({
      browsers: ['last 3 versions', 'ie > 9']
      }),
      cssnano()
      ];
      gulp.src('src/styles/main.scss')
      .pipe(sass().on('error', sass.logError))
      .pipe(postcss(processors))
      .pipe(gulp.dest('dist/files/styles/'));
      });


      and when I change
      gulp.watch('src/styles/**/*.scss', ['styles']);

      to
      gulp.watch('src/styles/**/*.scss', gulp.series('styles'));

      it just gives me a Starting 'default'... and after changing a file Starting 'styles'...

      with Gulp 3.9 it was



      Starting 'default'...
      Finished 'default' after 174 ms


      and after changing a file



      Starting 'styles'...
      Finished 'styles' after 561 μs


      I've now tried many different things but I just dont get it to work like it did before. I'm really thinking of switching over to webpack like the cool kids now. But Gulp always worked fine.


      Can someone explain to me what I'm doing wrong?







      npm gulp postcss






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Aug 30 '18 at 10:52









      obencsobencs

      2516




      2516
























          3 Answers
          3






          active

          oldest

          votes


















          1














          I just forgot to return...
          return gulp.watch('src/styles/**/*.scss', gulp.series('styles'));

          and
          return gulp.src('src/styles/main.scss')


          Complete code:



          var gulp = require('gulp');
          var sass = require('gulp-sass');
          var postcss = require('gulp-postcss');
          var autoprefixer = require('autoprefixer');
          var cssnano = require('cssnano');

          gulp.task('default', function () {
          return gulp.watch('src/styles/**/*.scss', gulp.series('styles'));
          });

          gulp.task('styles', function () {
          var processors = [
          autoprefixer({
          browsers: ['last 3 versions', 'ie > 9']
          }),
          cssnano()
          ];
          return gulp.src('src/styles/main.scss')
          .pipe(sass().on('error', sass.logError))
          .pipe(postcss(processors))
          .pipe(gulp.dest('dist/files/styles/'));
          });





          share|improve this answer
























          • Are you sure this is valid Gulp v4 syntax? You are not using built-in exports variable for declaring and exposing tasks.

            – Fusion
            Feb 3 at 14:47



















          0














          I struggled with this one myself..



          took me hours of headache only to find out that basically everything changes with v4.0



          I've run my code like this and it works perfectly...



          //Do everything once!
          gulp.task('default', function(){
          gulp.watch('src/styles/*.css', gulp.series('css')),
          gulp.watch('src/html/*.html', gulp.series('copyHTML')),
          gulp.watch('src/js/*.js', gulp.series('scripts')),
          gulp.watch('src/images/*', gulp.series('imageMIN'));
          return
          });





          share|improve this answer

































            0














            Can be used via event



            function watch() {
            const watcher = gulp.watch('src/styles/**/*.scss');
            watcher.on('change', function(path, stats) {
            styles(); //styles task
            });
            }

            exports.default = gulp.series(watch);





            share|improve this answer








            New contributor




            Vlone is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.





















              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52095228%2fgulp-v4-watch-task%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              I just forgot to return...
              return gulp.watch('src/styles/**/*.scss', gulp.series('styles'));

              and
              return gulp.src('src/styles/main.scss')


              Complete code:



              var gulp = require('gulp');
              var sass = require('gulp-sass');
              var postcss = require('gulp-postcss');
              var autoprefixer = require('autoprefixer');
              var cssnano = require('cssnano');

              gulp.task('default', function () {
              return gulp.watch('src/styles/**/*.scss', gulp.series('styles'));
              });

              gulp.task('styles', function () {
              var processors = [
              autoprefixer({
              browsers: ['last 3 versions', 'ie > 9']
              }),
              cssnano()
              ];
              return gulp.src('src/styles/main.scss')
              .pipe(sass().on('error', sass.logError))
              .pipe(postcss(processors))
              .pipe(gulp.dest('dist/files/styles/'));
              });





              share|improve this answer
























              • Are you sure this is valid Gulp v4 syntax? You are not using built-in exports variable for declaring and exposing tasks.

                – Fusion
                Feb 3 at 14:47
















              1














              I just forgot to return...
              return gulp.watch('src/styles/**/*.scss', gulp.series('styles'));

              and
              return gulp.src('src/styles/main.scss')


              Complete code:



              var gulp = require('gulp');
              var sass = require('gulp-sass');
              var postcss = require('gulp-postcss');
              var autoprefixer = require('autoprefixer');
              var cssnano = require('cssnano');

              gulp.task('default', function () {
              return gulp.watch('src/styles/**/*.scss', gulp.series('styles'));
              });

              gulp.task('styles', function () {
              var processors = [
              autoprefixer({
              browsers: ['last 3 versions', 'ie > 9']
              }),
              cssnano()
              ];
              return gulp.src('src/styles/main.scss')
              .pipe(sass().on('error', sass.logError))
              .pipe(postcss(processors))
              .pipe(gulp.dest('dist/files/styles/'));
              });





              share|improve this answer
























              • Are you sure this is valid Gulp v4 syntax? You are not using built-in exports variable for declaring and exposing tasks.

                – Fusion
                Feb 3 at 14:47














              1












              1








              1







              I just forgot to return...
              return gulp.watch('src/styles/**/*.scss', gulp.series('styles'));

              and
              return gulp.src('src/styles/main.scss')


              Complete code:



              var gulp = require('gulp');
              var sass = require('gulp-sass');
              var postcss = require('gulp-postcss');
              var autoprefixer = require('autoprefixer');
              var cssnano = require('cssnano');

              gulp.task('default', function () {
              return gulp.watch('src/styles/**/*.scss', gulp.series('styles'));
              });

              gulp.task('styles', function () {
              var processors = [
              autoprefixer({
              browsers: ['last 3 versions', 'ie > 9']
              }),
              cssnano()
              ];
              return gulp.src('src/styles/main.scss')
              .pipe(sass().on('error', sass.logError))
              .pipe(postcss(processors))
              .pipe(gulp.dest('dist/files/styles/'));
              });





              share|improve this answer













              I just forgot to return...
              return gulp.watch('src/styles/**/*.scss', gulp.series('styles'));

              and
              return gulp.src('src/styles/main.scss')


              Complete code:



              var gulp = require('gulp');
              var sass = require('gulp-sass');
              var postcss = require('gulp-postcss');
              var autoprefixer = require('autoprefixer');
              var cssnano = require('cssnano');

              gulp.task('default', function () {
              return gulp.watch('src/styles/**/*.scss', gulp.series('styles'));
              });

              gulp.task('styles', function () {
              var processors = [
              autoprefixer({
              browsers: ['last 3 versions', 'ie > 9']
              }),
              cssnano()
              ];
              return gulp.src('src/styles/main.scss')
              .pipe(sass().on('error', sass.logError))
              .pipe(postcss(processors))
              .pipe(gulp.dest('dist/files/styles/'));
              });






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Aug 30 '18 at 14:37









              obencsobencs

              2516




              2516













              • Are you sure this is valid Gulp v4 syntax? You are not using built-in exports variable for declaring and exposing tasks.

                – Fusion
                Feb 3 at 14:47



















              • Are you sure this is valid Gulp v4 syntax? You are not using built-in exports variable for declaring and exposing tasks.

                – Fusion
                Feb 3 at 14:47

















              Are you sure this is valid Gulp v4 syntax? You are not using built-in exports variable for declaring and exposing tasks.

              – Fusion
              Feb 3 at 14:47





              Are you sure this is valid Gulp v4 syntax? You are not using built-in exports variable for declaring and exposing tasks.

              – Fusion
              Feb 3 at 14:47













              0














              I struggled with this one myself..



              took me hours of headache only to find out that basically everything changes with v4.0



              I've run my code like this and it works perfectly...



              //Do everything once!
              gulp.task('default', function(){
              gulp.watch('src/styles/*.css', gulp.series('css')),
              gulp.watch('src/html/*.html', gulp.series('copyHTML')),
              gulp.watch('src/js/*.js', gulp.series('scripts')),
              gulp.watch('src/images/*', gulp.series('imageMIN'));
              return
              });





              share|improve this answer






























                0














                I struggled with this one myself..



                took me hours of headache only to find out that basically everything changes with v4.0



                I've run my code like this and it works perfectly...



                //Do everything once!
                gulp.task('default', function(){
                gulp.watch('src/styles/*.css', gulp.series('css')),
                gulp.watch('src/html/*.html', gulp.series('copyHTML')),
                gulp.watch('src/js/*.js', gulp.series('scripts')),
                gulp.watch('src/images/*', gulp.series('imageMIN'));
                return
                });





                share|improve this answer




























                  0












                  0








                  0







                  I struggled with this one myself..



                  took me hours of headache only to find out that basically everything changes with v4.0



                  I've run my code like this and it works perfectly...



                  //Do everything once!
                  gulp.task('default', function(){
                  gulp.watch('src/styles/*.css', gulp.series('css')),
                  gulp.watch('src/html/*.html', gulp.series('copyHTML')),
                  gulp.watch('src/js/*.js', gulp.series('scripts')),
                  gulp.watch('src/images/*', gulp.series('imageMIN'));
                  return
                  });





                  share|improve this answer















                  I struggled with this one myself..



                  took me hours of headache only to find out that basically everything changes with v4.0



                  I've run my code like this and it works perfectly...



                  //Do everything once!
                  gulp.task('default', function(){
                  gulp.watch('src/styles/*.css', gulp.series('css')),
                  gulp.watch('src/html/*.html', gulp.series('copyHTML')),
                  gulp.watch('src/js/*.js', gulp.series('scripts')),
                  gulp.watch('src/images/*', gulp.series('imageMIN'));
                  return
                  });






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jan 3 at 22:14









                  Dijkgraaf

                  7,48592745




                  7,48592745










                  answered Jan 3 at 21:51









                  RealMJDevRealMJDev

                  195




                  195























                      0














                      Can be used via event



                      function watch() {
                      const watcher = gulp.watch('src/styles/**/*.scss');
                      watcher.on('change', function(path, stats) {
                      styles(); //styles task
                      });
                      }

                      exports.default = gulp.series(watch);





                      share|improve this answer








                      New contributor




                      Vlone is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.

























                        0














                        Can be used via event



                        function watch() {
                        const watcher = gulp.watch('src/styles/**/*.scss');
                        watcher.on('change', function(path, stats) {
                        styles(); //styles task
                        });
                        }

                        exports.default = gulp.series(watch);





                        share|improve this answer








                        New contributor




                        Vlone is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                        Check out our Code of Conduct.























                          0












                          0








                          0







                          Can be used via event



                          function watch() {
                          const watcher = gulp.watch('src/styles/**/*.scss');
                          watcher.on('change', function(path, stats) {
                          styles(); //styles task
                          });
                          }

                          exports.default = gulp.series(watch);





                          share|improve this answer








                          New contributor




                          Vlone is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.










                          Can be used via event



                          function watch() {
                          const watcher = gulp.watch('src/styles/**/*.scss');
                          watcher.on('change', function(path, stats) {
                          styles(); //styles task
                          });
                          }

                          exports.default = gulp.series(watch);






                          share|improve this answer








                          New contributor




                          Vlone is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.









                          share|improve this answer



                          share|improve this answer






                          New contributor




                          Vlone is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.









                          answered 2 days ago









                          VloneVlone

                          1




                          1




                          New contributor




                          Vlone is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.





                          New contributor





                          Vlone is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.






                          Vlone is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52095228%2fgulp-v4-watch-task%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Mossoró

                              Error while reading .h5 file using the rhdf5 package in R

                              Pushsharp Apns notification error: 'InvalidToken'