Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.0.0 is throwing errors #2

Closed
kevinrenskers opened this issue Sep 9, 2014 · 22 comments
Closed

1.0.0 is throwing errors #2

kevinrenskers opened this issue Sep 9, 2014 · 22 comments

Comments

@kevinrenskers
Copy link

This is my gulp task:

gulp.task('less', function() {
    return gulp.src('src/assets/less/style.less')
        .pipe(plugins.sourcemaps.init())
        .pipe(plugins.less())
        .pipe(plugins.autoprefixer('last 2 versions'))
        .pipe(plugins.sourcemaps.write('./maps'))
        .pipe(gulp.dest('src/.tmp/styles'));
});

This worked fine with gulp-autoprefixer 0.0.10. After upgrading to 1.0.0 I am getting this error:

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, or the source map's "file" property. Both were omitted.
    at SourceMapGenerator_applySourceMap [as applySourceMap] (/Users/kevin/Workspace/sling-web/node_modules/gulp-autoprefixer/node_modules/vinyl-sourcemaps-apply/node_modules/source-map/lib/source-map/source-map-generator.js:170:17)
    at applySourceMap (/Users/kevin/Workspace/sling-web/node_modules/gulp-autoprefixer/node_modules/vinyl-sourcemaps-apply/index.js:11:15)
    at DestroyableTransform._transform (/Users/kevin/Workspace/sling-web/node_modules/gulp-autoprefixer/index.js:35:5)
    at DestroyableTransform.Transform._read (/Users/kevin/Workspace/sling-web/node_modules/gulp-autoprefixer/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:184:10)
    at DestroyableTransform.Transform._write (/Users/kevin/Workspace/sling-web/node_modules/gulp-autoprefixer/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:172:12)
    at doWrite (/Users/kevin/Workspace/sling-web/node_modules/gulp-autoprefixer/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:237:10)
    at writeOrBuffer (/Users/kevin/Workspace/sling-web/node_modules/gulp-autoprefixer/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:227:5)
    at DestroyableTransform.Writable.write (/Users/kevin/Workspace/sling-web/node_modules/gulp-autoprefixer/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:194:11)
    at write (/Users/kevin/Workspace/sling-web/node_modules/gulp-less/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:623:24)
    at flow (/Users/kevin/Workspace/sling-web/node_modules/gulp-less/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:632:7)
@battaglr
Copy link

battaglr commented Sep 9, 2014

Autoprefixer have changed its API, know you need yo pass the browsers like this:

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

If you want, you can still use the v0.0.10.

@battaglr battaglr closed this as completed Sep 9, 2014
@kevinrenskers
Copy link
Author

Sadly that doesn't solve the problem, I still get the same error about "applySourceMap requires either an explicit source file, or the source map's "file" property".

@battaglr battaglr reopened this Sep 9, 2014
@sindresorhus
Copy link
Owner

Can you try removing the less plugin and see if that changes anything?

@kevinrenskers
Copy link
Author

Eh not really as I don't have valid css files, only Less files, sorry.

@kevinrenskers
Copy link
Author

Ah wait I'll use a parsed version, d'oh :) Probably won't have time until tomorrow though.

@sindresorhus
Copy link
Owner

You also need to use the new method signature. See the readme.

@iam-msm
Copy link

iam-msm commented Sep 9, 2014

With previous version there was no problem. But now
console msg =>
Error in plugin 'gulp-autoprefixer'
SourceMapGenerator.prototype.applySourceMap requires either an explicit source file......

when using this

gulp.task('less', function() {
  return gulp.src('tmp/less/**/*.less')
    .pipe($.changed('build/css', {extension: '.css'}))
    .pipe($.sourcemaps.init())
    .pipe($.plumber(onErrors))
    .pipe($.less())
    .pipe($.autoprefixer({browsers: AUTOPREFIXER_BROWSERS}))
    .pipe($.csscomb())
    .pipe($.sourcemaps.write('.'))
    .pipe(gulp.dest('build/css'))
    .pipe($.filter('**/*.css'))
    .pipe(reload({stream: true}))
});

But with pure css gulp-autoprefixer doing his job and also sourcemaps

gulp.task('less', function() {
  return gulp.src('build/css')
    .pipe($.sourcemaps.init())
    .pipe($.autoprefixer({browsers: AUTOPREFIXER_BROWSERS}))
    .pipe($.csscomb())
    .pipe($.sourcemaps.write('.'))
    .pipe(gulp.dest('build/css/testing'))
});

Also withoud gulp-autoprefixer task, gulp-less is doing his job

gulp.task('less', function() {
  return gulp.src('tmp/less/**/*.less')
    .pipe($.changed('build/css', {extension: '.css'}))
    .pipe($.sourcemaps.init())
    .pipe($.plumber(onErrors))
    .pipe($.less())
    .pipe($.csscomb())
    .pipe($.sourcemaps.write('.'))
    .pipe(gulp.dest('build/css'))
});

@brandonb927
Copy link

Came here to voice my concern as well on this issue as I'm getting the same/a similar error message. It seems in my case is caused by autoprefixer

Gulp task

gulp.task('styles_compile', ['vendor_css', 'vendor_fonts'], function () {
  return gulp.src('src/styles/site.less')
    .pipe(sourcemaps.init())
    .pipe(less())
    .pipe(autoprefixer())
    .pipe(sourcemaps.write())
    .pipe(gulp.dest('public/assets/css'));
});

Stack trace

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, or the source map's "file" property. Both were omitted.
    at SourceMapGenerator_applySourceMap [as applySourceMap] (/project/path/node_modules/gulp-autoprefixer/node_modules/vinyl-sourcemaps-apply/node_modules/source-map/lib/source-map/source-map-generator.js:171:17)
    at applySourceMap (/project/path/node_modules/gulp-autoprefixer/node_modules/vinyl-sourcemaps-apply/index.js:11:15)
    at DestroyableTransform._transform (/project/path/node_modules/gulp-autoprefixer/index.js:35:5)
    at DestroyableTransform.Transform._read (/project/path/node_modules/gulp-autoprefixer/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:184:10)
    at DestroyableTransform.Transform._write (/project/path/node_modules/gulp-autoprefixer/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:172:12)
    at doWrite (/project/path/node_modules/gulp-autoprefixer/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:237:10)
    at writeOrBuffer (/project/path/node_modules/gulp-autoprefixer/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:227:5)
    at DestroyableTransform.Writable.write (/project/path/node_modules/gulp-autoprefixer/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:194:11)
    at write (/project/path/node_modules/gulp-less/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:623:24)
    at flow (/project/path/node_modules/gulp-less/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:632:7)

@sindresorhus
Copy link
Owner

Can you try putting console.log(file, file.sourceMap, res.map, res.map.toString()); above

applySourceMap(file, res.map.toString());
and paste in the output here?

@dfaivre
Copy link

dfaivre commented Sep 10, 2014

Console output:

<File "app.css" <Buffer 62 6f 64 79 20 7b 0a 20 20 63 6f 6c 6f 72 3a 20 67 72 61 79 3b 0a 7d 0a>>
{ version: 3,
  sources: [ 'app.less' ],
  names: [],
  mappings: 'AAMA;EACE,WAAA',
  sourcesContent: [ '@mycolor: blue;\r\n\r\n.make-blue(@color) {\r\n  color: @color;\r\n}\r\n\r\nbody {\r\n  color: gray;\r\n}' ] }
{ _file: 'app.css',
  _sourceRoot: null,
  _sources: { _array: [ 'app.css' ], _set: { '$app.css': 0 } },
  _names: { _array: [], _set: {} },
  _mappings:
   [ { generatedLine: 1,
       generatedColumn: 0,
       originalLine: 1,
       originalColumn: 0,
       source: 'app.css',
       name: null },
     { generatedLine: 2,
       generatedColumn: 2,
       originalLine: 2,
       originalColumn: 2,
       source: 'app.css',
       name: null },
     { generatedLine: 2,
       generatedColumn: 15,
       originalLine: 2,
       originalColumn: 14,
       source: 'appcss',
       name: null },
     { generatedLine: 3,
       generatedColumn: 2,
       originalLine: 3,
       originalColumn: 1,
       source: 'app.css',
       name: null } ],
  _sourcesContents: null }
{"version":3,"sources":["app.css"],"names":[],"mappings":"AAAA;EACE,aAAY;EACb","file":"app.css"}

@dfaivre
Copy link

dfaivre commented Sep 10, 2014

Looks like gulp-ng-annotate was having the same issue. Here's their workaround: Kagami/gulp-ng-annotate@2dd427d

That probalby won't work in this case, since the file.sourceMap.file property is already gone once it gets to gulp-autoprefixer. It could be an issue with vinyl-sourcemap-apply or it could be gulp-less not handling the gulp source map pipeline correctly?

@sindresorhus
Copy link
Owner

Thanks @dfaivre. I've opened a ticket here: gulp-sourcemaps/vinyl-sourcemaps-apply#1

@chiefjester
Copy link
Contributor

this is happening to me as well:

gulp.task('less', function () {
  gulp.src(['./less/**/*.less', '!./less/**/_*.less'])
    .pipe(sourcemaps.init())
    .pipe(less())
    .pipe(prefix())
    .pipe(sourcemaps.write())
    .pipe(gulp.dest('./css'));
});

getting

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, or the source map's "file" property. Both were omitted.

@chiefjester
Copy link
Contributor

@sindresorhus , the author of vinyl-sourcemap just said its not a bug on his end.
gulp-sourcemaps/vinyl-sourcemaps-apply#1

@dfaivre
Copy link

dfaivre commented Sep 19, 2014

As a stopgap, I ended up created a custom gulp-autoprefixer that resets the file property before it tries to apply source maps:

res = autoprefixer(fileOpts).process(file.contents.toString(), {
                map: file.sourceMap ? {prev: file.sourceMap} : false,
                from: file.relative,
                to: file.relative
            });

            file.contents = new Buffer(res.css);

            if (res.map && file.sourceMap) {
                if (!(file.sourceMap.file)) {
                    file.sourceMap.file = file.relative;
                }
                applySourceMap(file, res.map.toString());
            }

Is this really an issue with gulp-less not setting the file.sourceMap.file property? Should all plugins have to guard against this?

@sindresorhus
Copy link
Owner

@dfaivre It's an gulp-less issue and will be fixed as soon as gulp-community/gulp-less#85 is merged.

@chiefjester
Copy link
Contributor

@sindresorhus I just updated gulp-less to the one with gulp-community/gulp-less#85 and is now version 1.3.6.

It works but it throws a warning:
gulp-sourcemap-write: source file not found:/Users/xxx/...

If I remove gulp-autoprofexier plugin it works.

My current gulpfile.js

gulp.task('less', function () {
  gulp.src(['./assets/less/**/*.less', '!./assets/less/**/_*.less'])
    .pipe(sourcemaps.init())
    .pipe(less())
    .pipe(minifyCss())
    .pipe(prefix())
    .pipe(sourcemaps.write("./"))
    .pipe(gulp.dest('./assets/css'));
});

codekirei added a commit to codekirei/gulp-autoprefixer that referenced this issue Sep 20, 2014
@codekirei codekirei mentioned this issue Sep 20, 2014
@codekirei
Copy link
Contributor

@deezahyn Does this work for you, too? #3

@koistya
Copy link

koistya commented Sep 21, 2014

var gulp = require('gulp');
var $ = require('gulp-load-plugins')();

gulp.task('styles', function () {
  return gulp.src(src/'styles/bootstrap.less')
    .pipe($.sourcemaps.init())
    .pipe($.less())
    .pipe($.autoprefixer())
    .pipe($.sourcemaps.write());
    .pipe(gulp.dest('./build/css'));
});
$ gulp styles
[11:13:47] Using gulpfile gulpfile.js
[11:13:47] Starting 'styles'...
gulp-sourcemap-write: source file not found: src\styles\bootstrap.css
[11:13:49] Finished 'styles' after 1.97 s

gulp-autoprefixer 1.0.1, gulp-less 1.3.6, gulp-sourcemaps 1.2.2, OS: Windows

@chiefjester
Copy link
Contributor

@codekirei
Yes it removes the warning of "gulp-sourcemap-write: source file not found:" Not sure why you're PR seems failing the test.

chiefjester added a commit to chiefjester/gulp-autoprefixer that referenced this issue Sep 21, 2014
- Current build seems to fail.  It might have something to do with the
default option Default: ['> 1%', 'last 2 versions', 'Firefox ESR', 'Opera 12.1']
which may change over time.
- this commit updates the sourcemap file generated.
@koistya
Copy link

koistya commented Sep 22, 2014

Same error with gulp-autoprefixer 1.0.1 Does anyone else have this issue? Or, maybe, it only takes place on Windows machines?

If I comment out .pipe($.autoprefix()) the error messages goes away.

gulp-sourcemaps/gulp-sourcemaps#37 (comment)

That error message means that:

  • sourcesContent for one of the files is missing
  • sourcemaps.write() tries to fix that by loading the content of the source file, but it can not find it
    (probably because the path in sources is incorrect)

@sebastian-steinmann
Copy link

We have this issue too, and #3 seems to fix it for us.
(On windows)

codekirei added a commit to codekirei/gulp-autoprefixer that referenced this issue Sep 23, 2014
codekirei added a commit to codekirei/gulp-autoprefixer that referenced this issue Sep 26, 2014
DenisIzmaylov added a commit to DenisIzmaylov/gulp-autoprefixer that referenced this issue Oct 17, 2014
It seems troubles caused by vinyl-sourcemaps-apply module. With this fix it just works.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants