简体   繁体   English

是什么导致我的GULP gulpfile.js文件中出现“无效的顶级表达式”错误?

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

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: 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 Windows 7的

If you want to use the indented syntax (.sass) as the top level file, use 如果要使用缩进语法(.sass)作为顶级文件,请使用

pipe(sass({ indentedSyntax: true }))

instead of 代替

pipe(sass()) . pipe(sass())

Can you try to use the option sourceComments and set it to normal in your sass ? 你可以尝试使用该选项sourceComments并将其设置为normal在你的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 . 请参阅gulp-sass相关问题 Alternatively, you can still use gulp-ruby-sass . 或者,你仍然可以使用gulp-ruby-sass

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. 非常有趣的是,对我来说问题是插件gulp-sass忽略了顶级文件的扩展,无论如何都会解析为SCSS。

Includes worked correctly, so the solution was to make a one liner inclusion at the top. 包括正确的工作,所以解决方案是在顶部包含一个内衬。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM