9

I can't figure out what I'm doing wrong here. I'm getting a really odd error message when I try and create a sourcemap file using Gulp.

events.js:85
      throw er; // Unhandled 'error' event
            ^
CssSyntaxError: /www/static/sass/maps/main.css.map:1:198: Missed semicolon

I want them to be created in a separate .map file. I cannot understand why it's telling me there's an error in the file I've asked it to create...?

What am I doing wrong?

Here's my gulpfile.js:

var gulp = require('gulp'),
    sass = require('gulp-sass'),
    minifyCSS = require('gulp-minify-css'),
    autoprefixer = require('gulp-autoprefixer'),
    sourcemaps = require('gulp-sourcemaps'),
    input = 'static/sass/**/*.scss',
    output = 'static/css';

var sassOptions = {
    errLogToConsole: true,
    outputStyle: 'expanded'
};

gulp.task('sass', function() {
    return gulp
        .src(input)
        .pipe(sourcemaps.init())
        .pipe(sass(sassOptions).on('error', sass.logError))
        .pipe(sourcemaps.write('.'))
        .pipe(autoprefixer())
        .pipe(minifyCSS())
        .pipe(gulp.dest(output))
});

gulp.task('watch', function() {
    gulp.watch(input, ['sass']);
});

// Default task - Compile then set Watch
gulp.task('default', ['sass', 'watch']);
5
  • Why are you placing your source maps onto the production server at all? Commented Oct 23, 2015 at 12:46
  • @cimmanon I'm not placing my sourcemaps on any production server. What gave you that idea? Commented Oct 23, 2015 at 13:51
  • You did: "I want them to be created in a separate .map file so the average user won't see them when visiting the site". Why would the average user see the source map at all, unless it was on the production server? Commented Oct 23, 2015 at 13:52
  • @cimmanon By default the sourcemap is included inline within the CSS. I just want to separate it so I don't have to modify my gulpfile and recompile (for a sourcemap-less version) before every deployment. Commented Oct 23, 2015 at 13:53
  • @cimmanon I've removed the confusing sentence for you. Commented Oct 23, 2015 at 13:55

1 Answer 1

31

It turns out it was simply the placement of the line .pipe(sourcemaps.write('.')). Moving it solved the problem:

return gulp
    .src(input)
    .pipe(sourcemaps.init())
    .pipe(sass(sassOptions).on('error', sass.logError))
    .pipe(autoprefixer())
    .pipe(minifyCSS())
    .pipe(sourcemaps.write('.')) // This line moved to here
    .pipe(gulp.dest(output))

Would love to know why :-/

Sign up to request clarification or add additional context in comments.

4 Comments

same here, but no idea why the sourcemaps need to be in the end
@Jorre I believe sourcemaps.write() needs to come after autoprefixer() because autoprefixer attempts to add prefixes to the source map, which causes the error
@EddieHong Ah! Thank you for explaining that! It makes perfect sense.
Can you explain why sourcemaps.write needs to be at the end?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.