Last updated: Mar 7, 2024
Reading time·2 min
To solve the error "gulp-sass 5 does not have a default Sass compiler; please
set one yourself", make sure you have sass
and gulp-sass
installed and set
your import statement to
const sass = require('gulp-sass')(require('sass'));
.
gulp-sass 5 does not have a default Sass compiler; please set one yourself. Both the sass and node-sass packages are permitted. const sass = require('gulp-sass')(require('sass')); gulp-sass no longer has a default Sass compiler.
Open your terminal in your project's root directory (where your package.json
)
file is and then run the following command.
# with NPM npm install sass gulp-sass --save-dev # or with YARN yarn add sass gulp-sass --dev
Import gulp-sass
into your gulpfile.js
file and pass it to your compiler of
choice.
For example, if you use CommonJS, you'd use the following import statement.
// using CommonJS require() const sass = require('gulp-sass')(require('sass'));
If you use the ES6 Modules import/export syntax, you'd use something similar to the following.
// using ES6 imports import dartSass from 'sass'; import gulpSass from 'gulp-sass'; const sass = gulpSass(dartSass);
Note that when using Dart Sass, synchronous rendering is twice as fast as asynchronous rendering.
If you use node-sass
, make sure to correct your import statement.
import gulpSass from "gulp-sass"; import nodeSass from "node-sass"; const sass = gulpSass(nodeSass);
However, as shown on the NPM page of node-sass, the package is deprecated.
node-sass
continues to receive maintenance releases, however no additional
features will be added, so you should use the
Dart Sass package instead.
The Dart Sass package is named sass
and is installed by running the following
command.
# with NPM npm install --save-dev sass # or with YARN yarn add sass --dev
If you want to install the package globally so you have access to the sass
executable in your terminal, install sass
globally.
npm install -g sass
Note that gulp-sass
version 5 requires you to have a Node.js version greater
than 12.
You can check your Node version by issuing the following command.
node -v
As the npm page of gulp-sass states:
As of gulp-sass version 5, the package does not include a default Sass compiler.
You have to install one of node-sass
or sass
along with gulp-sass
.
You can learn more about the related topics by checking out the following tutorials: