Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialChristopher R
1,441 Pointsevents.js:160 throw er; // Unhandled 'error' even
I'm getting the above error in the console when running gulp minifyScripts:
"use strict";
var gulp = require('gulp'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename');
gulp.task("concatScripts", function() {
gulp.src([
'js/jquery.js',
'js/sticky/jquery.sticky.js',
'js/main.js'
])
.pipe(concat('app.js'))
.pipe(gulp.dest('js'));
});
gulp.task("minifyScripts", function() {
gulp.src("js/app.js")
.pipe(uglify())
.pipe(rename('app.min.js'))
.pipe(gulp.dest('js'));
});
gulp.task("default", ["hello"], function() {
console.log("the default task!!!!");
});
2 Answers
eck
43,038 PointsI think that uglify might be having an error, which is currently not being handled. If you try adding this to the uglify step you might be able to learn more about the nature of your error:
.pipe(uglify().on('error', function(e){
console.log(e);
}))
gulp.task("minifyScripts", function() {
gulp.src("js/app.js")
.pipe(uglify().on('error', function(e){
console.log(e);
}))
.pipe(rename('app.min.js'))
.pipe(gulp.dest('js'));
});
Christopher R
1,441 PointsThank you!
eck
43,038 Pointseck
43,038 PointsOh, I think I know where you went wrong. You are running
minifyScripts
but not theconcatScripts
task. Adding the concat task to your minify task could be the solution.gulp.task("minifyScripts", ["concatScripts"], function() {...
eck
43,038 Pointseck
43,038 PointsIf you pass an array of strings that match other tasks you have declared as the second argument in the
gulp.task
method then those will be run before that task.