gulp-rename icon indicating copy to clipboard operation
gulp-rename copied to clipboard

Error: write after end

Open ghost opened this issue 6 years ago • 13 comments

Hello,

I am trying to use this package as a stream for a Yeoman generator, to rename gitignore files on the fly: https://yeoman.io/authoring/file-system.html#transform-output-files-through-streams

this.registerTransformStream(rename(path => {
  if (path.extname === '.gitignore') {
    path.basename = '.gitignore';
    path.extname = '';
  }
}));

The error received in the terminal seems to come from readable-stream: Error [ERR_STREAM_WRITE_AFTER_END]: write after end

Related issue on yeoman repository: https://github.com/yeoman/yo/issues/577

The code posted above works fine with [email protected], but not with any more recent version.

I am wondering if you are aware of this issue, and what would be the difference. According to my very quick scan on the source code, I have only seen newer dependencies versions and a LICENSE file... Not sure exactly what is the cause of this issue.

v1.2.2 dependencies:

"devDependencies": {
  "gulp": ">=3.0.0",
  "gulp-sourcemaps": "^1.5.0",
  "gulp-util": "^3.0.4",
  "jshint": "^2.6.3",
  "map-stream": ">=0.0.4",
  "mocha": ">=1.15.0",
  "should": ">=2.1.0"
},

v1.4.0 dependencies:

"devDependencies": {
  "gulp": "^4.0.0",
  "gulp-sourcemaps": "^2.6.4",
  "jscs": "^3.0.0",
  "jshint": "^2.0.0",
  "map-stream": "^0.0.7",
  "mocha": "^5.0.0",
  "should": "^13.0.0",
  "vinyl": "^2.0.0"
},

I am also wondering if tthose differences between version 1.2.2 and the more recent ones such as the 1.4.0 currently published on NPM are accessible somewhere? https://www.npmjs.com/package/gulp-rename?activeTab=versions

Those new versions do not seem to be available as releases on this repository: https://github.com/hparra/gulp-rename/releases

ghost avatar Jun 17 '19 14:06 ghost

I'm having the same issue

alvaromartmart avatar Jun 28 '19 09:06 alvaromartmart

If you wish a quickfix @alvaromartmart, you can use v1.2.2 meanwhile:

"devDependencies": {
  "gulp-rename": "<=1.2.2"
}

ghost avatar Jun 28 '19 10:06 ghost

registerTransformStream with gulp-rename is still an issue even with gulp-rename v1.2.2. However, I get it working with glob.

const glob = require('glob');

writing() {
    const files = glob.sync('**', { dot: true, nodir: true, cwd: this.templatePath() })
    for (let i in files) {
        this.fs.copyTpl(
            this.templatePath(files[i]),
            this.destinationPath( this.props.destinationFolderPath + '\\' + files[i].replace(/__fileName__/g,this.props.fileName)),
            this.props
        )
    }
}

jariwalakrunal1983 avatar Nov 12 '19 04:11 jariwalakrunal1983

Still an issue with v2.0.0. With 1.2.2 it works for me.

StefanRutzmoser avatar Dec 05 '19 15:12 StefanRutzmoser

Having same issue, and what I've noticed is that it seems to be caused when you make changes to file object that is cloned originalFile.clone({ contents: false });

In my case I got it working by replacing gulp-rename with:

class MyTransformer extends Transform {
    constructor(props) {
        super({ objectMode: true });
        this.props = props;
    }

    _transform(chunk, encoding, callback) {
        for (const [pKey, pVal] of Object.entries(this.props)) {
            const regExp = new RegExp("{{" + pKey + "}}", "g");
            if (chunk.relative.match(regExp)) {
                chunk.path = path.join(chunk.base, chunk.relative.replace(regExp, pVal));
            }
        }

        callback(null, chunk);
    }
}

This seems to be working and I'm not getting any errors. As soon as I add chunk.clone({ contents: false }) and start using that it crashes. Without it it works.

danechitoaie avatar May 12 '20 11:05 danechitoaie

This is still an issue. Downgrading to <=1.2.2. worked for me

DFreds avatar Sep 23 '20 20:09 DFreds

+1 - stream never ending in 1.4.0 when file source >= 100k (approximately) downgrading fixes the problem

bendenoz avatar Dec 22 '20 15:12 bendenoz

Cam everyone who is having issues post what version of node you are using?

yocontra avatar Dec 22 '20 17:12 yocontra

had issue with both node 8 and 10

bendenoz avatar Dec 22 '20 18:12 bendenoz

@bendenoz Can you try it with the latest version of node and see if that resolves it?

Node 8 is a year past end of life as well so not something we're trying to support right now, but node 10 not working is something we will fix if its an issue there.

yocontra avatar Dec 22 '20 20:12 yocontra

As another thing you could try if you want to be a guinea pig - on line 3 of this package replace require('stream') with require('readable-stream') and see if that does anything.

yocontra avatar Dec 22 '20 20:12 yocontra

@contra , readable-stream doesn't change anything, but the problem seems to lie in the originalFile.clone call. If I remove it and use the file originalFile directly it works. Tried changing options but didn't help.

The file is created by an old version of gulp-util / vinyl so it might be part of the problem

bendenoz avatar Dec 23 '20 13:12 bendenoz

suryadev99

LeeNFr avatar Sep 12 '23 05:09 LeeNFr