2

Here is my code

gulp.task('js', function () {
return gulp.src(['public/js/angular.js','public/js/app.js', 'public/js/**/*.js'])
    .pipe(plumber({
        errorHandler: function(err){
            console.log(err);
            this.emit('end');
        }
    }))
    .pipe(concat('filename.min.js'))
    .pipe(uglify().on('error', gutil.log))
    .pipe(gulp.dest('public/js') //destination of new file
    .pipe(notify({ message: 'Finished minifying JavaScript'})))

gulp.task('watch', function(){
    gulp.watch('app/assets/sass/**/*', ['css']);
    gulp.watch('public/js/**/*', ['js']);
});

Console error after change made to any js file:

/projects/miche-web/public/js/miche.min.js: Unexpected token name «replace», expected punc «,»] message: '/Users/projects/miche-web/public/js/miche.min.js: Unexpected token name «replace», expected punc «,»', fileName: '/Users/projects/miche-web/public/js/miche.min.js', lineNumber: 247,

However, the file is blank so I can't reference an error on line 247.

Any thoughts?

9
  • The error occurs on the generated file or in the gulp task? Commented Feb 10, 2016 at 23:35
  • It occurs in the gulp task but references the file that is created with the concat(). Error references a line number for that file, but the file is blank. I'm baffled. Commented Feb 10, 2016 at 23:37
  • You have no example above that shows a gulp "watch" so please post more code or we can't help you. Commented Feb 10, 2016 at 23:46
  • Thanks. More code added. Hope it's helpful. Commented Feb 10, 2016 at 23:51
  • I'm getting the impression that my js files have errors in them and it's referencing the line number of where that code will go after it's minified. Kind of difficult to debug. Commented Feb 10, 2016 at 23:55

1 Answer 1

1

You have a syntax error in your pipe call. Observe the following...

.pipe(gulp.dest('public/js') //destination of new file

=>

.pipe(gulp.dest('public/js')) //destination of new file

notice the missing ) on your initial function call

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for catching that! Oddly enough it was still working. I discovered the error because I found some PHP code that was not removed from the JavaScript. It could not minify because of that but now it works fine after I removed it.
hehe strange that it works. Either way you solved it and that's what is important!
Exactly! Very odd one here. Now I know for next time that I see this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.