问题
I get an error after I start gulp. I have taken out all other plugins to find problem:
[gulp-sass] source string:1: error: invalid top-level expression
gulpfile.js:
var gulp = require('gulp');
var sass = require('gulp-sass');
gulp.task('sass', function() {
gulp.src('app/assets/sass/styles.sass')
.pipe(sass({
errLogToConsole: true
}))
.pipe(gulp.dest('public_html/assets/css'))
});
gulp.task('default', ['sass'], function() {
gulp.watch("app/assets/sass/*.sass", ['sass']);
});
Windows 7
回答1:
If you want to use the indented syntax (.sass) as the top level file, use
pipe(sass({ indentedSyntax: true }))
instead of
pipe(sass())
.
回答2:
Can you try to use the option sourceComments
and set it to normal
in your sass
? It seems to have some problems if you don't pass it.
So try to change your task as follow :
gulp.task('sass', function () {
gulp.src('app/assets/sass/styles.sass')
.pipe(sass({
errLogToConsole: true,
sourceComments : 'normal'
}))
.pipe(gulp.dest('public_html/assets/css'))
});
See the related issue of gulp-sass. Alternatively, you can still use gulp-ruby-sass.
回答3:
Hilariously, the problem for me was that the plugin gulp-sass
ignores the extension of the top level file and parses as SCSS no matter what.
Includes worked correctly, so the solution was to make a one liner inclusion at the top.
来源:https://stackoverflow.com/questions/24225680/what-is-causing-this-invalid-top-level-expression-error-in-my-gulp-gulpfile-js