1
votes

I am currently setting up my gulpfile and im having a problem with gulp-sass when the watch task is running the scss task.

This is how my gulpfile.js looks:

var gulp = require('gulp'),
    plumber = require('gulp-plumber'),
    sass = require('gulp-sass'),
    sourcemaps = require('gulp-sourcemaps');

var onError = function(err) {
    console.log(err);
};

var bases = {
    dist: './dist/',
    src: './src/'
};

var paths = {
 sass: [bases.src + 'scss/base.scss'],
 sourcemaps: '/'
};

gulp.task('scss', function(){
    return gulp.src(paths.sass)
    .pipe(plumber({
        errorHandler: onError
    }))
    .pipe(sourcemaps.init())
    .pipe(sass({
        sourcemap: true,
        style: 'expanded',
        sourceComments: 'normal',
        onError: onError
    }))
    .pipe(sourcemaps.write(paths.sourcemaps))
    .pipe(gulp.dest(bases.dist + 'css/'))
});

gulp.task('watch', function(){
    gulp.watch(bases.src + 'scss/**/*.scss', ['scss'])

});

gulp.task('default', ['scss','watch']);

base.scss only contains this: (also tried full path and without fileext. same result)

@import 'modules/modules_base.scss';

The error i'm getting in console:

[18:54:13] Finished 'scss' after 12 ms
[18:54:15] Starting 'scss'...
{ [Error: src\scss\base.scss
  1:9  file to import not found or unreadable: ./src/scss/modules/modules_base.scss
Current dir: ]
  message: 'src\\scss\\base.scss\n  1:9  file to import not found or unreadable: ./src/scss/modules/modules_base.scss\nCurrent dir: ',
  column: 9,
  line: 1,
  file: 'stdin',
  status: 1,
  messageFormatted: '\u001b[4msrc\\scss\\base.scss\u001b[24m\n\u001b[90m  1:9\u001b[39m  file to import not found or unreadable: ./src/scss/modules/modules_base.scss\nCurrent dir: ',
  name: 'Error',
  stack: 'Error: src\\scss\\base.scss\n  1:9  file to import not found or unreadable: ./src/scss/modules/modules_base.scss\nCurrent dir: \n    at options.error (c:\\Code\\colorpicker\\node_modules\\gu
lp-sass\\node_modules\\node-sass\\lib\\index.js:276:32)',
  showStack: false,
  showProperties: true,
  plugin: 'gulp-sass' }

The basic error is: 1:9 File to import not found or unreadable: ./src/scss/modules/modules_base.scss

the structure of the app:

-component
   gulpfile.js
   -dist
       -css
           base.css
           base.css.map
   -src
       -scss
           base.scss
           -modules
                -modules_base.scss 

The error only happens when i save the modules_base.scss and the watch task is fired, and never when im running the default task.

all suggestions are appreciated!

Notes: Node -v : 0.12.0 Gulp: 3.8.11 gulp-sass: 2.0.1

1
Found out that if i removed the "return" from the "scss" task, the task doesnt stop so im still able to use is by just hitting ctrl + s a couple of times. Not a fix but now it atleast worksRinrub

1 Answers

0
votes

Are you using vscode? I found this on github

gulp.task('sass', function () {
    return gulp.src(SCSS_SRC)
        .pipe(wait(500))
        .pipe(sass({
            outputStyle: 'compressed',
            includePaths: ['./bower_components/susy/sass', './bower_components/breakpoint-sass/stylesheets']
        }).on('error', sass.logError))
        .pipe(concat('style.css'))
        .pipe(autoprefixer({
            browsers: ['>1%', 'last 2 versions'],
            cascade: false
        }))
        .pipe(gulp.dest('./dist/css'));
});

Basically

I was having this issue when saving in sublime. The first time the file changed, gulp watch would fire before the file either completed saving, or was unreadable when lib-sass started. I added a 50ms delay to the pipe which seems to work.

Have you tried this?

edit - I use run-sequence to ensure processes finish before running things that require them. Check it out

gulp.task('default',function(callback){
    runSequence('clean-folder','css','js'['responsive-jpg','responsive-webp','copy-data']),callback
});

Basically clean-folder runs and deletes stuff I want a redo on, then css compiles. Nothing after will run until run-sequence gets the callback that all of the scss has been transpiled.