gulp-sass 5 does not have a default Sass compiler; 是什么问题?
const {src, dest, series, watch} = require('gulp') const del = require('del') //gulp-uglify => plugins.uglify = require('gulp-uglify') const plugins = require('gulp-load-plugins')() //压缩js uglify function js(cb){ src('js/*.js') // 下一个处理环节 .pipe(plugins.uglify()) .pipe(dest('./dist/js')) cb() } //对sccs/less 编译,输出css文件 function css(cb){ src('css/*.scss') .pipe(plugins.sass({outputStyle: 'compressed'})) .pipe(plugins.autoprefixer({ cascade: false, remove: false })) .pipe(dest('./dist/css')) cb() } //监听这些文件变化 function watcher(){ watch('js/*.js', js) watch('css/*.scss', js) } //删除dist目录的内容 function clean(cb){ del('./dist') cb() } exports.scripts = js exports.styles = css exports.clean = clean exports.default = function(){ clean, js, css, watcher }
wanglimindeMacBook-Air:demo1 wanglimin$ npx gulp styles
[07:37:06] Using gulpfile ~/Desktop/大前端练习/demo1/gulpfile.js
[07:37:06] Starting 'styles'...
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'));
[07:37:06] The following tasks did not complete: styles
[07:37:06] Did you forget to signal async completion?
请教一下老师上面的提示是什么问题?
尝试过的解决方式:
我直接把 “
var sass = require('gulp-sass')(require('sass'));
”
复制粘贴到 gulpfile.js
再运行 nxp gulp scripts 爆出来下面的错误提示
谢谢!
wanglimindeMacBook-Air:demo1 wanglimin$ npx gulp styles
{ Error: Cannot find module 'sass'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:690:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/Users/wanglimin/Desktop/大前端练习/demo1/gulpfile.js:4:33)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3) code: 'MODULE_NOT_FOUND' }
正在回答
你是不是没有装sass?
cnpm i -D sass
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星