gulp-sass 5 does not have a default Sass compiler; please set one yourself

18,342

Solution 1

I had this problem and found that adding the standard sass npm npm install --save-dev sass and then adding the second section of the error message to my variable so that it looks like this const sass = require('gulp-sass')(require('sass')); worked.

Solution 2

If you, like me, use a modular system. Then this solution should help you!
You need to install SASS
It is also necessary that the gulp-sass be installed

import pkg from 'gulp';
const { src, dest, series, watch } = pkg;
import concat from 'gulp-concat'

import dartSass from 'sass'
import gulpSass from 'gulp-sass'
const sass = gulpSass(dartSass)

function scss() {
    return src('app/scss/**/*.scss', { sourcemaps: true })
        .pipe(sass.sync().on('error', sass.logError)) // scss to css
        .pipe(concat('style.min.css'))
        .pipe(dest(config.build.style, { sourcemaps: '../sourcemaps/' }))
}

async function builds() { scss() }
export { builds }
Share:
18,342

Related videos on Youtube

Zia Ansari
Author by

Zia Ansari

Updated on June 04, 2022

Comments

  • Zia Ansari
    Zia Ansari almost 2 years

    Error in plugin "gulp-sass" Message:

    gulp-sass 5 does not have a default Sass compiler; please set one yourself. Both the sass and node-sass packages are permitted. For example, in your gulpfile:

    var sass = require('gulp-sass')(require('sass'));
    

    This is my code below . It says var sass = require('gulp-sass')(require('sass')); in the error but I am using import and none of the solution worked for me I am new to this and the cli version is 2.3.0 local version is 4.0.2 please give me a solution I am stuck here for days

    import gulp from 'gulp';
    import sass from 'gulp-sass';
    import yargs from 'yargs';
    
    
    const PRODUCTION = yargs.argv.prod;
    
    export const styles = () => {
        return gulp.src('src/assets/scss/bundle.scss')
          .pipe(sass().on('error', sass.logError))
          .pipe(gulp.dest('dist/asset/css'));
    }
    
  • Paul
    Paul over 2 years
    I fixed this but only by installing SASS and not the 2nd thing. Adding (require('sass')) to the end of my sass = statement just returns TypeError: sass is not a function.
  • KulaGGin
    KulaGGin over 2 years
    It's so bad that after installing the gulp-sass I have to get an error and then google how to fix it. Basically, after installing gulp-sass everyone installs a broken plugin.
  • Shashank Bhatt
    Shashank Bhatt over 2 years
    As it says to set compiler in your code, sass.compiler = require('sass'); also works fine.