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 trial

JavaScript Gulp Basics Gulp your JavaScript Workflow Minifying JavaScript Files

Margaret Godowns
Margaret Godowns
6,268 Points

Minifying Javascript Files Error dest.on is not a function

I'm trying to minify and rename a javascript file using gulp and am getting a weird error. Below is my code:

'use strict';

var gulp = require('gulp'),
    concat = require('gulp-concat'),
    uglify = require('gulp-uglify'), 
    //I know the teacher has require('gulp-rename') here but that's not the name of the module and I get an error when I have that
    rename = require('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("This is the default task!");
});

And here is the error in the terminal after I run gulp minifyScripts

TypeError: dest.on is not a function
    at DestroyableTransform.Readable.pipe (/Users/margaretgodowns/Sites/treehouse-gulp-basics/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:533:8)
    at Gulp.<anonymous> (/Users/margaretgodowns/Sites/treehouse-gulp-basics/gulpfile.js:21:6)
    at module.exports (/Users/margaretgodowns/Sites/treehouse-gulp-basics/node_modules/orchestrator/lib/runTask.js:34:7)
    at Gulp.Orchestrator._runTask (/Users/margaretgodowns/Sites/treehouse-gulp-basics/node_modules/orchestrator/index.js:273:3)
    at Gulp.Orchestrator._runStep (/Users/margaretgodowns/Sites/treehouse-gulp-basics/node_modules/orchestrator/index.js:214:10)
    at Gulp.Orchestrator.start (/Users/margaretgodowns/Sites/treehouse-gulp-basics/node_modules/orchestrator/index.js:134:8)
    at /usr/local/lib/node_modules/gulp/bin/gulp.js:129:20
    at doNTCallback0 (node.js:430:9)
    at process._tickCallback (node.js:359:13)
    at Function.Module.runMain (module.js:459:11)

I tried to compare it to the downloadable files in the exercise, but the gulpfile.js stops at uglify. Also, everything works fine when I remove .pip(gulp.desk"js"). Anyone have any ideas?

Thank you!

2 Answers

Margaret Godowns
Margaret Godowns
6,268 Points

I figured it out. I had installed rename by typing

    npm install gulp rename --save-dev

when I should have put

    npm install gulp-rename --save-dev

Face palm.

Lol I still made this exact mistake even though I read your question beforehand!

Double face palm.

and I have another hint for you when you type in the ('something') is preffer using the double quote like this ("something") all the time to prevent some error, hope help you ...