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 Clean not working

Second time i post this not getting any answer

gulp clean
module.js:557
    throw err;
    ^

Error: Cannot find module 'gulp-sourcemaps'
    at Function.Module._resolveFilename (module.js:555:15)
    at Function.Module._load (module.js:482:25)
    at Module.require (module.js:604:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/hugo/Desktop/treehouse-gulp-basics/gulpfile.js:8:12)
    at Module._compile (module.js:660:30)
    at Object.Module._extensions..js (module.js:671:10)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)

This is my gulp.js file dont know why its throwing error

"use strict";

var gulp = require('gulp'),
  concat = require('gulp-concat'),
  uglify = require('gulp-uglify'),
  rename = require('gulp-rename'),
    sass = require('gulp-sass'),
    maps = require('gulp-sourcemaps'),
     del = require('del');

gulp.task("concatScripts", function() {
    return gulp.src([
        'js/jquery.js',
        'js/sticky/jquery.sticky.js',
        'js/main.js'
        ])
    .pipe(maps.init())
    .pipe(concat('app.js'))
    .pipe(maps.write('./'))
    .pipe(gulp.dest('js'));
});

gulp.task("minifyScripts", ["concatScripts"], function() {
  return gulp.src("js/app.js")
    .pipe(uglify())
    .pipe(rename('app.min.js'))
    .pipe(gulp.dest('js'));
});

gulp.task('compileSass', function() {
  return gulp.src("scss/application.scss")
      .pipe(maps.init())
      .pipe(sass())
      .pipe(maps.write('./'))
      .pipe(gulp.dest('css'));
});

gulp.task('watchSass', function() {
  gulp.watch('scss/**/*.scss', ['compileSass']);
});

gulp.task('clean', function() {
    del("dist");
});

gulp.task("build", ['minifyScripts', 'compileSass'], function(){
  return gulp.src(["css/application.css", "js/app.min.js", "index.html",
                    "img/**", "fonts/**"],  { base: "./" })
                    .pipe(gulp.dest("dist"));
});

gulp.task("default", ["build"]);

3 Answers

Adam Beer
Adam Beer
11,314 Points

Is not this the final code? Try this way. This working for me. Please change your code in the thirty-second line. Like this:

return gulp.src("_sass/application.scss")

Yeah thats the code. Thanks for the quick reply. No its still not working for me. Throwing the same error

Adam Beer
Adam Beer
11,314 Points

Please finish the video and then try it out. This is This is my the last couple of lines:

gulp.task('compileSass', function() {
    return gulp.src("_sass/application.scss")
        .pipe(maps.init())
        .pipe(sass())
        .pipe(maps.write('./'))
        .pipe(gulp.dest('css'));
});

gulp.task('watchFiles', function() {
    gulp.watch('scss/**/*.scss', ['compileSass']);
    gulp.watch('js/main.js', ['concatScripts']);
});

gulp.task('clean', function() {
    del(['dist', 'css/application.css*', 'js/app*.js*']);
});

gulp.task("build", ['minifyScripts', 'compileSass'], function() {
    return gulp.src(["css/application.css", "js/app.js", 'index.html',
                    "img/**", "fonts/**"], { base: './'})
                .pipe(gulp.dest('dist'));
});

gulp.task('serve', ['watchFiles']);

gulp.task("default", ["clean"], function() {
    gulp.start('build');
});

Ok so the gulp-sourcemap had been uninstalled for some reason I reinstalled it and now seems to be working. Thanks for the help Adam!

Adam Beer
Adam Beer
11,314 Points

Great news! Good learning!