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

Empty file & gulp-sourcemaps never completes #122

Closed
TuckerWhitehouse opened this issue Jan 16, 2015 · 19 comments
Closed

Empty file & gulp-sourcemaps never completes #122

TuckerWhitehouse opened this issue Jan 16, 2015 · 19 comments

Comments

@TuckerWhitehouse
Copy link

If I try to compile an empty less file and use gulp-sourcemaps, the task starts but never completes.

@stephenlacy
Copy link
Contributor

Please add the following:

  • gulpfile
  • gulp, gulp-less, and gulp-sourcemap versions

@TuckerWhitehouse
Copy link
Author

"gulp": "^3.8.10",
"gulp-less": "^2.0.1",
"gulp-load-plugins": "^0.8.0",
"gulp-sourcemaps": "^1.3.0"
var gulp = require('gulp');
var plugins = require('gulp-load-plugins')();

gulp.task('less', function () {
  gulp.src('public/**/*.less', { base: '.' })
    .pipe(plugins.sourcemaps.init())
    .pipe(plugins.less())
    .pipe(plugins.sourcemaps.write())
    .pipe(gulp.dest('.'));
});

Also tried without gulp-load-plugins, but it made no difference.

var gulp = require('gulp');
var less = require('gulp-less');
var sourcemaps = require('gulp-sourcemaps');

gulp.task('less', function () {
  gulp.src('public/**/*.less', { base: '.' })
    .pipe(sourcemaps.init())
    .pipe(less())
    .pipe(sourcemaps.write())
    .pipe(gulp.dest('.'));
});

@stephenlacy
Copy link
Contributor

Can you add a example .less file?

@TuckerWhitehouse
Copy link
Author

The issue presents itself when compiling an empty less file.

@TuckerWhitehouse
Copy link
Author

I created a simple gist that I hope helps demonstrate the issue. I added an error listener and include the output from that in the gist.
https://gist.github.com/TuckerWhitehouse/9181bf9bb31b0fb40617

@HaNdTriX
Copy link
Contributor

I am having the same issue.
Does any of you know a proper workaround?

@HaNdTriX
Copy link
Contributor

For now I resoved the issue on empty files with gulp-clip-empty-files.

gulp.task('styles:dev', function() {
  return gulp.src(src)
    .pipe(watch(src))

    // Remove empty files from stream
    // To prevent sourcemaps less issue
    // https://github.com/plus3network/gulp-less/issues/122
    .pipe(clip())

    // Report errors but don't disconnect the stream
    .pipe(plumber())

    // Initialize sourcemaps
    .pipe(sourcemaps.init())

    // Compile less
    .pipe(less({
      plugins: [autoprefix]
    }))

    // Write out the sourcemaps
    .pipe(sourcemaps.write())

    // Finally, output the files to the build directory
    .pipe(gulp.dest(dest))

    // Notify Livereload
    .pipe(livereload());

});

But this doesn't work if the content of the file is an empty css rule:

body{

}

@yocontra
Copy link
Member

@HaNdTriX Does the autoprefix plugin support sourcemaps? Try using gulp-autoprefixer instead. I had the same issue with gulp-stylus where some of the plugins were mangling sourcemaps

@HaNdTriX
Copy link
Contributor

I am using less-plugin-autoprefix and it works fine.

The issue also exist without less plugins.

@yocontra
Copy link
Member

@HaNdTriX I have received issues that say sourcemaps in less-plugin-autoprefix are broken/non-existant. Could you double check?

@TuckerWhitehouse
Copy link
Author

The original issue I filed was without less-plugin-autoprefix, and the addition of less-plugin-autoprefix or gulp-autoprefix does not appear to have any impact.

@yocontra
Copy link
Member

Can you try this in 2.0.3? I think it was an error reporting issue

@yocontra
Copy link
Member

This got fixed in less/less.js#2439

@heikki
Copy link

heikki commented Feb 15, 2015

Looks like it's broken different way now:

∴ gulp-less-test gulp less
[09:32:06] Using gulpfile ~/Desktop/gulp-less-test/gulpfile.js
[09:32:06] Starting 'less'...
[09:32:06] Finished 'less' after 8.65 ms

undefined:1
undefined
^
SyntaxError: Unexpected token u
    at Object.parse (native)
    at /Users/heikki/Desktop/gulp-less-test/node_modules/gulp-less/node_modules/accord/lib/adapters/less.js:48:32
    at /Users/heikki/Desktop/gulp-less-test/node_modules/gulp-less/node_modules/less/lib/less/render.js:35:17
    at /Users/heikki/Desktop/gulp-less-test/node_modules/gulp-less/node_modules/less/lib/less/parse.js:63:17
    at Object.finish [as _finish] (/Users/heikki/Desktop/gulp-less-test/node_modules/gulp-less/node_modules/less/lib/less/parser/parser.js:183:28)
    at Object.ImportVisitor._onSequencerEmpty (/Users/heikki/Desktop/gulp-less-test/node_modules/gulp-less/node_modules/less/lib/less/visitors/import-visitor.js:35:14)
    at ImportSequencer.tryRun (/Users/heikki/Desktop/gulp-less-test/node_modules/gulp-less/node_modules/less/lib/less/visitors/import-sequencer.js:50:14)
    at Object.ImportVisitor.run (/Users/heikki/Desktop/gulp-less-test/node_modules/gulp-less/node_modules/less/lib/less/visitors/import-visitor.js:29:25)
    at Object.Parser.parse (/Users/heikki/Desktop/gulp-less-test/node_modules/gulp-less/node_modules/less/lib/less/parser/parser.js:189:22)
    at Object.parse (/Users/heikki/Desktop/gulp-less-test/node_modules/gulp-less/node_modules/less/lib/less/parse.js:61:18)
{
  "dependencies": {
    "gulp": "^3.8.11",
    "gulp-less": "^3.0.0",
    "gulp-sourcemaps": "^1.3.0"
  }
}
var gulp = require('gulp');
var less = require('gulp-less');
var sourcemaps = require('gulp-sourcemaps');

gulp.task('less', function () {
  gulp.src('public/**/*.less', { base: '.' })
    .pipe(sourcemaps.init())
    .pipe(less())
    .pipe(sourcemaps.write())
    .pipe(gulp.dest('.'));
});

@yocontra
Copy link
Member

@Jenius looks like an accord bug to me

@yocontra
Copy link
Member

@Jenius https://github.com/jenius/accord/blob/master/lib/adapters/less.coffee#L24 is the culprit. Probably passing undefined to JSON.parse

@heikki if you add a guard for undefined around that JSON.parse call does it fix the problem?

@heikki
Copy link

heikki commented Feb 15, 2015

@contra if (options.sourceMap && res.map) { on line above seems to make it pass.

@yocontra
Copy link
Member

@heikki Maybe send a PR? Would get it fixed a lot quicker

@jescalan
Copy link
Contributor

Thanks for the PR, fixed and shipped as accord@0.15.1

yocontra pushed a commit that referenced this issue Feb 22, 2015
Update accord to ^0.15.1 to finalize #122
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants