admin管理员组

文章数量:1185843

Getting a strange error using a basic gulp/express build watch.

Directory Layout

 project/
   - sass/
      - style.scss
   - gulpfile.js
   - index.html

Gulpfile.js

var gulp         = require('gulp'),
    sass         = require('gulp-ruby-sass'),
    autoprefixer = require('gulp-autoprefixer'),
    minifycss    = require('gulp-minify-css'),
    rename       = require('gulp-rename');

gulp.task('express', function() {
  var express = require('express');
  var app = express();
  app.use(require('connect-livereload')({port: 4002}));
  app.use(express.static(__dirname));
  app.listen(4000);
});

var tinylr;
gulp.task('livereload', function() {
  tinylr = require('tiny-lr')();
  tinylr.listen(4002);
});

function notifyLiveReload(event) {
  var fileName = require('path').relative(__dirname, event.path);

  tinylr.changed({
    body: {
      files: [fileName]
    }
  });
}

gulp.task('styles', function() {
    return gulp.src('sass/*.scss')
      .pipe(sass({ style: 'expanded', sourcemap: false }))
      .pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1'))
      .pipe(gulp.dest('css'))
      .pipe(rename({suffix: '.min'}))
      .pipe(minifycss())
      .pipe(gulp.dest('css'));
});

gulp.task('watch', function() {
  gulp.watch('sass/*.scss', ['styles']);
  gulp.watch('*.html', notifyLiveReload);
  gulp.watch('css/*.css', notifyLiveReload);
});

gulp.task('default', ['styles', 'express', 'livereload', 'watch'], function() {

});

Style.scss

body { position: relative; }

The express server/livereload works fine, but when it tries to compile the stylesheet I'm getting this error (even with sourcemap: false)

gulp-ruby-sass: write style.css.map

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: <LOCAL_PATH_HERE>/style.css.map:3:1: Unknown word

Getting a strange error using a basic gulp/express build watch.

Directory Layout

 project/
   - sass/
      - style.scss
   - gulpfile.js
   - index.html

Gulpfile.js

var gulp         = require('gulp'),
    sass         = require('gulp-ruby-sass'),
    autoprefixer = require('gulp-autoprefixer'),
    minifycss    = require('gulp-minify-css'),
    rename       = require('gulp-rename');

gulp.task('express', function() {
  var express = require('express');
  var app = express();
  app.use(require('connect-livereload')({port: 4002}));
  app.use(express.static(__dirname));
  app.listen(4000);
});

var tinylr;
gulp.task('livereload', function() {
  tinylr = require('tiny-lr')();
  tinylr.listen(4002);
});

function notifyLiveReload(event) {
  var fileName = require('path').relative(__dirname, event.path);

  tinylr.changed({
    body: {
      files: [fileName]
    }
  });
}

gulp.task('styles', function() {
    return gulp.src('sass/*.scss')
      .pipe(sass({ style: 'expanded', sourcemap: false }))
      .pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1'))
      .pipe(gulp.dest('css'))
      .pipe(rename({suffix: '.min'}))
      .pipe(minifycss())
      .pipe(gulp.dest('css'));
});

gulp.task('watch', function() {
  gulp.watch('sass/*.scss', ['styles']);
  gulp.watch('*.html', notifyLiveReload);
  gulp.watch('css/*.css', notifyLiveReload);
});

gulp.task('default', ['styles', 'express', 'livereload', 'watch'], function() {

});

Style.scss

body { position: relative; }

The express server/livereload works fine, but when it tries to compile the stylesheet I'm getting this error (even with sourcemap: false)

gulp-ruby-sass: write style.css.map

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: <LOCAL_PATH_HERE>/style.css.map:3:1: Unknown word
Share Improve this question asked Nov 17, 2014 at 18:31 elzielzi 5,6727 gold badges39 silver badges62 bronze badges 5
  • It's pretty clearly telling you that there's something wrong on style.css.map, line 3, char 1. Have you checked your mapfile? – mpowered Commented Nov 17, 2014 at 18:40
  • Map file does not exist. It's creating that in tmp, and previously it was autocreated without errors. i'm suspecting this update to sass is relevant but haven't found solution. – elzi Commented Nov 17, 2014 at 18:43
  • 3 Removing the pipe to gulp-autoprefixer allows it to build successfully. hmm. – elzi Commented Nov 17, 2014 at 18:49
  • getting the same error (without express) – ProblemsOfSumit Commented Nov 19, 2014 at 11:26
  • Does the answer I provided below not resolve it for you? – elzi Commented Nov 19, 2014 at 18:03
Add a comment  | 

5 Answers 5

Reset to default 17

Disabling sourcemaps is some kind of mystery right now. You have to do it like this

.pipe(sass({ "sourcemap=none": true }))

Source

Not entirely sure why this fixes it, but changing the autoprefixer pipe to:

.pipe(autoprefixer({
     browsers: ['last 2 versions'],
     cascade: false
}))

and putting it before the sass pipe (top) allows it to build succesfully.

I fixed this problem keeping the source maps and using gulp-filter:

var filter = require('gulp-filter')
var filterCSS = filter('**/*.css');

gulp.task('styles', function() {
    return gulp.src('sass/*.scss')
      .pipe(sass({ style: 'expanded', sourcemap: true }))

      // Filters only css files before auto prefixing
      .pipe(filterCSS)
      .pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1'))
      .pipe(filterCSS.restore())

      .pipe(gulp.dest('css'))
      .pipe(rename({suffix: '.min'}))
      .pipe(minifycss())
      .pipe(gulp.dest('css'));
});

I was having the same issue with the gulp-ruby-sass plugin. I found this blog post which explains that there are a couple of bugs in the gulp-ruby-sass plugin regarding source maps. They have both been closed a little over a week ago. If you upgrade to gulp-ruby-sass~1.0.0-alpha this should fix the issues your having with source maps.

If that doesn't work the article I linked to above shows how to use the gulp-sass plugin which which doesn't have the source map issue.

Try upgrading to gulp-ruby-sass 1.0.0-alpha. It uses gulp-sourcemaps and should avoid all iterations of this problem.

本文标签: javascriptgulp with gulprubysass Error stylecssmap31 Unknown wordStack Overflow