Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

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

like image 688
Joel Z. Avatar asked Jun 15 '14 01:06

Joel Z.


People also ask

What is a gulpfile in JavaScript?

Although a few utilities are provided to simplify working with the filesystem and command line, everything else you write is pure JavaScript. A gulpfile is a file in your project directory titled gulpfile.js (or capitalized as Gulpfile.js, like Makefile), that automatically loads when you run the gulp command.

How does gulp handle errors?

Working with Gulp, you begin to run into a slightly annoying problem, and that is how gulp handles errors. If you mess up your code, Gulp plugins will not be sure what to do and will return an error. Once the error is returned, Gulp logs it and break the stream. In order to fix the error, you will have to fix the error, then restart your stream.

Where do I put a gulp file in WordPress?

Here’s an example file structure using the WordPress file structure: You could add the gulp file into your theme folder or your wp-content folder instead. However, since I keep the wp-content file in my git repository as a whole, I keep the gulpfile.js file outside of my git repository by keeping it in the root of the project.

How do I use gulp to watch for changes in JavaScript?

2) Minify the javascript into an all-min.js file. 3) Leave the resulting file in the /js folder. Open the Console, navigate to the folder that gulpfile.js is in, and type “gulp watch”. In the watch task, we allow the computer to watch for changes and run these tasks anytime they apply.


1 Answers

If you want to use the indented syntax (.sass) as the top level file, use

pipe(sass({ indentedSyntax: true }))

instead of

pipe(sass()).

like image 134
cloudlena Avatar answered Oct 13 '22 05:10

cloudlena