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

Error: write after end #84

Open
ghost opened this issue Jun 17, 2019 · 13 comments
Open

Error: write after end #84

ghost opened this issue Jun 17, 2019 · 13 comments

Comments

@ghost
Copy link

ghost commented Jun 17, 2019

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:
yeoman/yo#577

The code posted above works fine with gulp-rename@1.2.2, 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

@alvaromartmart
Copy link

I'm having the same issue

@ghost
Copy link
Author

ghost commented Jun 28, 2019

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

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

@jariwalakrunal1983
Copy link

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
        )
    }
}

@StefanRutzmoser
Copy link

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

rohit-gohri added a commit to danger/generator-danger-plugin that referenced this issue Feb 15, 2020
orta pushed a commit to danger/generator-danger-plugin that referenced this issue Feb 16, 2020
* fix(build): update typescript dep and add @types/node

Updated typescript to v3.x, and add node types to fix tsc build

Closes #25

* build(dependencies): update dev dependencies and related configs

re #25

* improvement: update dev dependencies and related configs in default template

* fix: fix tooling configs not in default

* build: remove typescript (not needed) and add semantic release script

* build: update babel and babelrc

* test: ignore built and template tests

* chore: Update yeoman dependencies and lock gulp-rename

yeoman relevant issue: yeoman/yo#577
gulp-rename: relevant issue: hparra/gulp-rename#84

* test: update snapshots

* ci: Test on modern nodejs version

* chore: Update vscode jest debug config

* ci: use yarn in travis ci

* fix: downgrade commitzen, didn't work with node<=10

* refactor: remove node<10 support

BREAKING CHANGE: Removed support for node<10 in the generator and the generated plugins too

* fix: update babel config and dependencies in template
@danechitoaie
Copy link

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.

@DFreds
Copy link

DFreds commented Sep 23, 2020

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

@bendenoz
Copy link

bendenoz commented Dec 22, 2020

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

@yocontra
Copy link
Collaborator

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

@bendenoz
Copy link

had issue with both node 8 and 10

@yocontra
Copy link
Collaborator

@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
Copy link
Collaborator

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.

@bendenoz
Copy link

@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

@LeeNFr
Copy link

LeeNFr commented Sep 12, 2023

suryadev99

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

8 participants