本文介绍了Gulp-sass无法编译scss文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我使用Gulp编译我的sass到css。一个简单的任务在 _ / sass 目录中编译 style.scss 文件,并将输出保存到项目。 style.scss 仅用于导入 _ / sass 目录中的其他文件。 当我从命令行( $ gulp )运行默认任务时,我得到一个错误,说明sass无法编译。它包括在下面的完整。我已从包含的文件中删除所有内容,然后再次运行任务。我仍然收到相同的错误(我在网上读的一个建议,这可能会测试编码问题,我不完全理解编码,以及如何可能破坏我的情况)。 我也从命令行 $ sass _ / sass / style.scss style.css 运行,它与包含的文件中的内容完美。这告诉我gulp sass插件本身的一个问题。 来自gulpfile.js的相关片段: var gulp = require('gulp'); var sass = require('gulp-sass'); //编译sass文件 gulp.task('sass',function(){ gulp.src('./_/ sass / style.scss') .pipe(sass()) .pipe(gulp.dest('./')); }); //默认任务(当你运行`gulp'时调用) gulp.task('default',function(){ gulp.run('sass') ; //观察文件并运行任务,如果他们改变 gulp.watch(['./_/ sass / style.scss'],function(){ gulp.run('sass'); })}); style.scss的全部内容: / * RESET * / @import'_ / sass / reset'; / * TYPOGRAPHY * / @import'_ / sass / typography'; / * MOBILE * / @import'_ / sass / mobile'; / * MAIN * / @import'_ / sass / main'; 目录结构: ├──_ │├──inc ││├──stuff │├──js ││├──其他。 js │└──sass │├──main.scss │├──mobile.scss │├──print.scss │├─ ─reset.scss │├──style.scss │└──typography.scss ├──gulpfile.js └──style.css 终端机出现: [gulp]使用文件/Users/jeshuamaxey/project/dir/path/gulpfile.js [gulp]工作目录更改为/ Users / jeshuamaxey / project / dir / path / html5reset [ gulp]运行'默认'... [gulp]运行'sass'... [gulp]完成'sass'在3.18 ms [gulp]完成'默认' ms stream.js:94 throw er; //管道中的未处理流错误。 ^ 源字符串:11:错误:要导入的文件未找到或无法读取:'reset' includePaths 选项作为参数: gulp.src('./_/ sass / style.scss') .pipe(sass({includePaths :['_ / sass /']})) .pipe(gulp.dest('./')); ...应该为你做。 根据 https://github.com/dlmanning / gulp-sass / issues / 1 I'm using Gulp to compile my sass into css. A simple task compiles the style.scss file in the _/sass directory and saves the output into the root of the project. style.scss is used merely to import other files in the _/sass directory.When I run the default task from the command line ($ gulp) I get an error that the sass can't compile. It is included below in full. I have removed all content from the included files and run the task again. I still receive the same error (something I read online suggested this might test for an encoding issue. I don't fully understand encoding and how that might break things in my scenario).I've also run from the command line $ sass _/sass/style.scss style.css which works perfectly with content in the included files. This suggests to me a problem with the gulp sass plugin itself.The relevant snippets from gulpfile.js:var gulp = require('gulp');var sass = require('gulp-sass');// Compile sass filesgulp.task('sass', function () { gulp.src('./_/sass/style.scss') .pipe(sass()) .pipe(gulp.dest('./'));});// The default task (called when you run `gulp`)gulp.task('default', function() { gulp.run('sass'); // Watch files and run tasks if they change gulp.watch(['./_/sass/style.scss'], function() { gulp.run('sass'); })});The full contents of style.scss:/* RESET */@import '_/sass/reset';/* TYPOGRAPHY */@import '_/sass/typography';/* MOBILE */@import '_/sass/mobile';/* MAIN */@import '_/sass/main';The directory structure:├── _│ ├── inc│ │ ├── stuff│ ├── js│ │ ├── otherstuff.js│ └── sass│ ├── main.scss│ ├── mobile.scss│ ├── print.scss│ ├── reset.scss│ ├── style.scss│ └── typography.scss├── gulpfile.js└── style.cssTerminal spits out:[gulp] Using file /Users/jeshuamaxey/project/dir/path/gulpfile.js[gulp] Working directory changed to /Users/jeshuamaxey/project/dir/path/html5reset[gulp] Running 'default'...[gulp] Running 'sass'...[gulp] Finished 'sass' in 3.18 ms[gulp] Finished 'default' in 8.09 msstream.js:94 throw er; // Unhandled stream error in pipe. ^source string:11: error: file to import not found or unreadable: 'reset' 解决方案 Keep your imports as is, just pass the includePaths option in your gulp sass module as an argument:gulp.src('./_/sass/style.scss') .pipe(sass({ includePaths : ['_/sass/'] })) .pipe(gulp.dest('./'));...should do it for you.As per https://github.com/dlmanning/gulp-sass/issues/1 这篇关于Gulp-sass无法编译scss文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-29 19:08