16

Gulp-sass recently updated to version 5.0. They describe that it doesn't include a compiler anymore and they say you have to install in separately.

They have documentation on how to let gulp-sass require the compiler with this piece of code.

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

But im using import() instead of require() and i can't find out how to translate the code they provided with require() to import().

This is also the error i get:

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'));

For now i rolled back to version 4.1.1 which included the compiler but i would like to update it to version 5.0 at some point.

Murrt
  • 163
  • 1
  • 1
  • 5

5 Answers5

15
import gulpSass from "gulp-sass";
import nodeSass from "node-sass";
    
const sass = gulpSass(nodeSass);

Try this. But I still don't know if this is the best.

  • I know "node-sass" should be deprecated. Just an example. use "dart-sass" or "sass"
NaBeomki
  • 206
  • 1
  • 7
  • 2
    How fix problem if `gulpfile.js` don't want add import ? `import gulpSass from "gulp-sass"; ^^^^^^ SyntaxError: Cannot use import statement outside a module ` – BlackStar1991 Aug 04 '21 at 08:30
6

From sass github repository

import dartSass from 'sass';
import gulpSass from 'gulp-sass';
const sass = gulpSass( dartSass );
Web Master
  • 327
  • 1
  • 3
  • 13
2

You cannot use import statement within the body of your code. It must be used at the beginning of the file (see https://flexiple.com/javascript-require-vs-import/#:~:text=One%20of%20the%20major%20differences,js%20extension%20as%20opposed%20to%20.)

If you or anyone is looking for how to implement the gulp code. I found a direction on Reddit https://www.reddit.com/r/webdev/comments/o9okup/error_with_gulpsass_setup/ a user - "LessRain" provided an answer:

To install node-sass navigate to your project directory in terminal and run this command: npm install gulp gulp-sass node-sass gulp-concat --save-dev

Then you can swap sass = require('gulp-sass'); for const sass = require("gulp-sass")(require("node-sass"));

In my case that code went into a gulpfile.js file but since it is part of a statement I had no need for "const"

let gulp = require('gulp'),sass = require("gulp-sass")(require("node-sass")),...
Ojchris
  • 188
  • 1
  • 3
  • 11
0

(from error description)

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

Viorel
  • 73
  • 1
  • 4
  • why do we need two brackets at the end if only one is open? – Alex78191 Feb 02 '22 at 16:53
  • 1
    The answer was from npm: https://www.npmjs.com/package/gulp-sass. You can try without that brackets but I suppose that it's used for multiple tasks. – Viorel Feb 03 '22 at 15:52
0

What worked for me was using npm install sass not using -g.