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

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


Solution 1:[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:[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 }

Solution 3:[3]

if I used gulp-sass

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

else if I used node-sass

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

on another state when I used required

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

Solution 4:[4]

I had the same problem. This is my solution:

npm install sass
npm install gulp-sass
My version sass -"^1.51.0" and gulp-sass - "^5.1.0" in package.json

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

gulp.task('styles', () => (
    gulp.src('src/**/*.scss')
         .pipe(sass())
         .pipe(concat('style.css'))
         .pipe(gulp.dest('public'))
))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dharman
Solution 2 Artem
Solution 3 hossein naghneh
Solution 4 Dmytro Kukharuk