scniro/gulp-clean-css

file.contents.toString() throws exception after 4.x release

mynameismaosheng opened this issue · 19 comments

gulp.task("cssmin", () => { return gulp .src(["src/public/stylesheets/**/*"]) .pipe(cleanCSS({ compatibility: "ie8" })) .pipe(gulp.dest("src/dist/css")); });
execute
gulp cssmin
c8c62c09d44b0d58ca14f70c46c040a
aefc70a75e761a27e026f52dc54a95e

I have switched the version to 3.9.3.
The error is gone

@mynameismaosheng interesting error. Which node version are you using? I may need to look into this. I cut a major release a month or so back and haven't heard any fallout yet. I see you've resolved your issue but I'd like to keep this open until I can get a better sense of what's going on...

@mynameismaosheng interesting error. Which node version are you using? I may need to look into this. I cut a major release a month or so back and haven't heard any fallout yet. I see you've resolved your issue but I'd like to keep this open until I can get a better sense of what's going on...

This error occurs with version 4.0.0

@mynameismaosheng sorry, I meant, which node version are you running?

@mynameismaosheng sorry, I meant, which node version are you running?

node v10.13.0

I believe I'm able to replicate this both using node v10.13.0 (the current package version on Fedora 29) and on v11.6.0.

Switching to 3.10.0 also fixes the issue for me.

@mynameismaosheng @Silarn sorry for the late reply. This should be fixed in the 4.0.1 release I've cut just now.

I just placed the empty string check back and all seems well. Did you have some empty files, perhaps not obvious, lying around for your tasks to pick up? Only reasoning I can see file.contents being undefined...

Anyways, can you give it a shot and let me know if the issue is fixed? Thanks!

thank you for your help,V4.0.0 was indeed fixed, but in v4.0.1 folders are also treated as files

@mynameismaosheng can you please clarify if you are still getting the same error in 4.0.1 as you were when you opened this issue? The following error should be fixed...

Cannot read property toString of null

What exactly are you now experiencing - and what are your expectations?

Yes, thank you very much. The problem has been solved.

I'm not able to install this with NPM, the package version doesn't seem to be updated. I will apply the change and test it manually, though.

Well, I had a couple issues going on. At some point extra files were compiled into a subdirectory due to a bad setup. So our gulp task was including an additional directory, which is probably what was causing the issue. I'm not sure what else changed that it was ignoring the directories in previous versions. Fixing our own setup helped to resolve the issue here, but if the input glob contains a directory v4.x is failing while v3.x was okay.

With these changes applied I get an error like this (without making the necessary changes to correct the issue): Error: EISDIR: illegal operation on a directory, open '/path/to/globbed/directory'

🤦‍♂️ @Silarn wow I forgot to publish, major facepalm. I'll be sure to do that this evening when I can get to it. I'm also going to reopen the issue as it doesn't seem clear that it's been resolved. I'll look into what's going on with the directory now.

Is it that empty directories are causing issues? I'll have to go back and check the diff. Sorry for the inconvenience while I try to unscrew things...

It wasn't an empty directory in my case. I believe it's trying to parse the directory as a target file rather than ignoring it or reading the files in it.

I don't know why? I can't reproduce this problem anymore, but it does exist.
9945e0ccc21730bf868d197fabf677e
Src folder compressed and output to dist.
I hope it will help you to sort out the problems.

I have the same problem with my project.
For now, I'm using the

gulp-if

plugin to check file.contents.

Example:

var gulp = require('gulp'),
    gulpif = require('gulp-if'),
    cleanCSS = require('gulp-clean-css'),
    rename = require('gulp-rename'),
    vinylfs = require('vinyl-fs');

function isNull(file) {
    return file.contents === null;
}

gulp.task('minCss', function () {
    return vinylfs.src([paths.css, '!' + paths.minCss], { base: '.' })
        .pipe(rename({ suffix: '.min' }))
        .pipe(gulpif(!isNull, cleanCSS({ keepSpecialComments: false })))
        .pipe(vinylfs.dest('.', { overwrite: false }));
});

@joaobhering @mynameismaosheng @Silarn Hey guys... I'm still looking into this. I've tried to replicate all of the file structures here that's been reported to cause the issue and I am unable to reproduce this. Still happy to help, but I may need a fully contained working example. If one of you can throw together a bare-bones repository that replicated the error I'll fix it ASAP.

I tried writing some tests in the project but still cannot reproduce. PR's always welcome too if you can identify what's causing this!

Hi, I've the same problem:

gulp-clean-css: 4.0.0
Node.js: 11.11
Ubuntu 16.04

This way I get the same error:

gulp.src(
    'assets/themes/base/styles/**'
)
.pipe(
    cleanCss()
)

I tried it with only 1 scss in the directory containing this:

body {
  color: red;
}

But if I specify the filename or filter for scss files (there are no other files in the directory), it works:

'assets/themes/base/styles/*.scss'
'assets/themes/base/styles/file.scss'

Hope this helps

@Allain55 @joaobhering @mynameismaosheng @Silarn This should be fixed via #71 and is available in the 4.1.0 release