gulp-sass 5 does not have a default Sass compiler [Solved]

avatar
Borislav Hadzhiev

Last updated: May 10, 2023
2 min

banner

# gulp-sass 5 does not have a default Sass compiler [Solved]

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

shell
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 an run the following command.

shell
# with NPM npm install sass gulp-sass --save-dev # or with YARN yarn add sass gulp-sass --dev

install sass and gulp sass

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.

gulpfile.js
// 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.

gulpfile.js
// 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.

index.js
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.

shell
# 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.

shell
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.

shell
node -v

check your node version

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.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.