What is causing this “invalid top-level expression” error in my GULP gulpfile.js file?

 ̄綄美尐妖づ 提交于 2019-12-08 19:11:03

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!