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

Unhandled 'error' event error in gulp 5 #2802

Closed
4 tasks done
marekdedic opened this issue May 4, 2024 · 5 comments
Closed
4 tasks done

Unhandled 'error' event error in gulp 5 #2802

marekdedic opened this issue May 4, 2024 · 5 comments

Comments

@marekdedic
Copy link

Before you open this issue, please complete the following tasks:

  • use the search bar at the top of the page to search this repository for similar issues or discussions that have already been opened.
  • if you are looking for help from the gulp team or community, open a discussion.
  • if you think there is a problem with the plugin you're using, open a discussion.
  • if you think there is a bug in our code, open this issue.

What were you expecting to happen?

I updated my repo from gulp 4 to gulp 5 (scout-handbook/odymaterialy.skauting.cz#12), I expected no errors.

What actually happened?

node:events:496
      throw er; // Unhandled 'error' event
      ^

<ref *2> Error: Writable stream closed prematurely
    at Pipeline.done (/home/user/odymaterialy.skauting.cz/node_modules/streamx/index.js:444:43)
    at PassThrough.emit (node:events:530:35)
    at PassThrough.emit (node:domain:551:15)
    at emitCloseNT (node:internal/streams/destroy:147:10)
    at process.processTicksAndRejections (node:internal/process/task_queues:81:21)
Emitted 'error' event on Domain instance at:
    at Transform.emit (node:domain:539:12)
    at ReadableState.afterDestroy (/home/user/odymaterialy.skauting.cz/node_modules/streamx/index.js:493:19)
    at Transform._destroy (/home/user/odymaterialy.skauting.cz/node_modules/streamx/index.js:629:5)
    at ReadableState.updateNonPrimary (/home/user/odymaterialy.skauting.cz/node_modules/streamx/index.js:386:16)
    at ReadableState.update (/home/user/odymaterialy.skauting.cz/node_modules/streamx/index.js:367:71)
    at ReadableState.updateReadNT (/home/user/odymaterialy.skauting.cz/node_modules/streamx/index.js:536:10)
    at process.processTicksAndRejections (node:internal/process/task_queues:77:11) {
  domainEmitter: <ref *1> Transform {
    _events: [Object: null prototype] {
      newListener: [Function: newListener],
      pipe: [Function: bound onceWrapper] { listener: [Function: onPipe] }
    },
    _eventsCount: 2,
    _maxListeners: undefined,
    _duplexState: 459316,
    _readableState: ReadableState {
      stream: [Circular *1],
      queue: FastFIFO {
        hwm: 16,
        head: FixedFIFO {
          buffer: [ undefined, undefined, <14 empty items> ],
          mask: 15,
          top: 2,
          btm: 2,
          next: null
        },
        tail: FixedFIFO {
          buffer: [ undefined, undefined, <14 empty items> ],
          mask: 15,
          top: 2,
          btm: 2,
          next: null
        },
        length: 0
      },
      highWaterMark: 0,
      buffered: 0,
      readAhead: true,
      error: [Circular *2],
      pipeline: Pipeline {
        from: [Circular *1],
        to: null,
        afterPipe: null,
        error: [Circular *2],
        pipeToFinished: false
      },
      byteLength: [Function: defaultByteLength],
      map: null,
      pipeTo: <ref *3> Composer {
        _events: [Object: null prototype] {
          newListener: [ [Function: newListener], [Function: removeSink] ],
          removeListener: [Function: removeSink],
          piping: [Function: markSink],
          finish: [Function: bound finished],
          drain: [Function: bound afterDrain],
          end: [Function: bound onceWrapper] {
            listener: [Function: bound remove]
          }
        },
        _eventsCount: 6,
        _maxListeners: undefined,
        _duplexState: 17236508,
        _readableState: ReadableState {
          stream: [Circular *3],
          queue: FastFIFO {
            hwm: 16,
            head: [FixedFIFO],
            tail: [FixedFIFO],
            length: 0
          },
          highWaterMark: 0,
          buffered: 0,
          readAhead: true,
          error: [Circular *2],
          pipeline: Pipeline {
            from: null,
            to: null,
            afterPipe: null,
            error: [Circular *2],
            pipeToFinished: true
          },
          byteLength: [Function: defaultByteLength],
          map: null,
          pipeTo: PassThrough {
            _events: [Object],
            _readableState: [ReadableState],
            _writableState: [WritableState],
            allowHalfOpen: true,
            _maxListeners: 0,
            _eventsCount: 7,
            add: [Function: add],
            isEmpty: [Function: isEmpty],
            [Symbol(shapeMode)]: true,
            [Symbol(kCapture)]: false,
            [Symbol(kCallback)]: null
          },
          afterRead: [Function: bound afterRead],
          afterUpdateNextTick: [Function: bound updateReadNT]
        },
        _writableState: WritableState {
          stream: [Circular *3],
          queue: FastFIFO {
            hwm: 16,
            head: [FixedFIFO],
            tail: [FixedFIFO],
            length: 0
          },
          highWaterMark: 0,
          buffered: 0,
          error: [Circular *2],
          pipeline: Pipeline {
            from: [Circular *1],
            to: null,
            afterPipe: null,
            error: [Circular *2],
            pipeToFinished: false
          },
          drains: null,
          byteLength: [Function: defaultByteLength],
          map: null,
          afterWrite: [Function: bound afterWrite],
          afterUpdateNextTick: [Function: bound updateWriteNT]
        },
        _writable: <ref *4> Transform {
          _events: [Object: null prototype] {
            newListener: [Function: newListener],
            drain: [Function: bound _continueWrite],
            finish: [Function: bound _maybeFinal],
            error: [Array],
            close: [Function: bound destroy]
          },
          _eventsCount: 5,
          _maxListeners: undefined,
          _duplexState: 17236508,
          _readableState: ReadableState {
            stream: [Circular *4],
            queue: [FastFIFO],
            highWaterMark: 0,
            buffered: 0,
            readAhead: true,
            error: Error: Stream was destroyed
                at Object.<anonymous> (/home/user/odymaterialy.skauting.cz/node_modules/streamx/index.js:2:26)
                at Module._compile (node:internal/modules/cjs/loader:1369:14)
                at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)
                at Module.load (node:internal/modules/cjs/loader:1206:32)
                at Module._load (node:internal/modules/cjs/loader:1022:12)
                at Module.require (node:internal/modules/cjs/loader:1231:19)
                at require (node:internal/modules/helpers:179:18)
                at Object.<anonymous> (/home/user/odymaterialy.skauting.cz/node_modules/glob-stream/index.js:9:16)
                at Module._compile (node:internal/modules/cjs/loader:1369:14)
                at Module._extensions..js (node:internal/modules/cjs/loader:1427:10),
            pipeline: [Pipeline],
            byteLength: [Function: defaultByteLength],
            map: null,
            pipeTo: [Transform],
            afterRead: [Function: bound afterRead],
            afterUpdateNextTick: [Function: bound updateReadNT]
          },
          _writableState: WritableState {
            stream: [Circular *4],
            queue: [FastFIFO],
            highWaterMark: 0,
            buffered: 0,
            error: Error: Stream was destroyed
                at Object.<anonymous> (/home/user/odymaterialy.skauting.cz/node_modules/streamx/index.js:2:26)
                at Module._compile (node:internal/modules/cjs/loader:1369:14)
                at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)
                at Module.load (node:internal/modules/cjs/loader:1206:32)
                at Module._load (node:internal/modules/cjs/loader:1022:12)
                at Module.require (node:internal/modules/cjs/loader:1231:19)
                at require (node:internal/modules/helpers:179:18)
                at Object.<anonymous> (/home/user/odymaterialy.skauting.cz/node_modules/glob-stream/index.js:9:16)
                at Module._compile (node:internal/modules/cjs/loader:1369:14)
                at Module._extensions..js (node:internal/modules/cjs/loader:1427:10),
            pipeline: null,
            drains: null,
            byteLength: [Function: defaultByteLength],
            map: null,
            afterWrite: [Function: bound afterWrite],
            afterUpdateNextTick: [Function: bound updateWriteNT]
          },
          _transformState: TransformState {
            data: null,
            afterTransform: [Function: bound afterTransform],
            afterFinal: null
          },
          _transform: [Function: normalize],
          [Symbol(shapeMode)]: false,
          [Symbol(kCapture)]: false
        },
        _readable: <ref *5> Transform {
          _events: [Object: null prototype] {
            newListener: [Function: newListener],
            data: [Function: bound _pushData],
            end: [Function: bound _pushEnd],
            error: [Array],
            close: [Array],
            finish: [Array],
            drain: [Function: bound afterDrain]
          },
          _eventsCount: 7,
          _maxListeners: undefined,
          _duplexState: 17238300,
          _readableState: ReadableState {
            stream: [Circular *5],
            queue: [FastFIFO],
            highWaterMark: 0,
            buffered: 0,
            readAhead: true,
            error: Error: Stream was destroyed
                at Object.<anonymous> (/home/user/odymaterialy.skauting.cz/node_modules/streamx/index.js:2:26)
                at Module._compile (node:internal/modules/cjs/loader:1369:14)
                at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)
                at Module.load (node:internal/modules/cjs/loader:1206:32)
                at Module._load (node:internal/modules/cjs/loader:1022:12)
                at Module.require (node:internal/modules/cjs/loader:1231:19)
                at require (node:internal/modules/helpers:179:18)
                at Object.<anonymous> (/home/user/odymaterialy.skauting.cz/node_modules/glob-stream/index.js:9:16)
                at Module._compile (node:internal/modules/cjs/loader:1369:14)
                at Module._extensions..js (node:internal/modules/cjs/loader:1427:10),
            pipeline: null,
            byteLength: [Function: defaultByteLength],
            map: null,
            pipeTo: null,
            afterRead: [Function: bound afterRead],
            afterUpdateNextTick: [Function: bound updateReadNT]
          },
          _writableState: WritableState {
            stream: [Circular *5],
            queue: [FastFIFO],
            highWaterMark: 0,
            buffered: 0,
            error: Error: Stream was destroyed
                at Object.<anonymous> (/home/user/odymaterialy.skauting.cz/node_modules/streamx/index.js:2:26)
                at Module._compile (node:internal/modules/cjs/loader:1369:14)
                at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)
                at Module.load (node:internal/modules/cjs/loader:1206:32)
                at Module._load (node:internal/modules/cjs/loader:1022:12)
                at Module.require (node:internal/modules/cjs/loader:1231:19)
                at require (node:internal/modules/helpers:179:18)
                at Object.<anonymous> (/home/user/odymaterialy.skauting.cz/node_modules/glob-stream/index.js:9:16)
                at Module._compile (node:internal/modules/cjs/loader:1369:14)
                at Module._extensions..js (node:internal/modules/cjs/loader:1427:10),
            pipeline: [Pipeline],
            drains: null,
            byteLength: [Function: defaultByteLength],
            map: null,
            afterWrite: [Function: bound afterWrite],
            afterUpdateNextTick: [Function: bound updateWriteNT]
          },
          _transformState: TransformState {
            data: null,
            afterTransform: [Function: bound afterTransform],
            afterFinal: null
          },
          _transform: [Function: writeFile],
          [Symbol(shapeMode)]: false,
          [Symbol(kCapture)]: false
        },
        _isPipeline: true,
        _pipelineMissing: 2,
        _writeCallback: null,
        _finalCallback: null,
        _ondata: [Function: bound _pushData],
        _onend: [Function: bound _pushEnd],
        _ondrain: [Function: bound _continueWrite],
        _onfinish: [Function: bound _maybeFinal],
        _onerror: [Function: bound destroy],
        _onclose: [Function: bound destroy],
        [Symbol(shapeMode)]: false,
        [Symbol(kCapture)]: false
      },
      afterRead: [Function: bound afterRead],
      afterUpdateNextTick: [Function: bound updateReadNT]
    },
    _writableState: WritableState {
      stream: [Circular *1],
      queue: FastFIFO {
        hwm: 16,
        head: FixedFIFO {
          buffer: [ <16 empty items> ],
          mask: 15,
          top: 0,
          btm: 0,
          next: null
        },
        tail: FixedFIFO {
          buffer: [ <16 empty items> ],
          mask: 15,
          top: 0,
          btm: 0,
          next: null
        },
        length: 0
      },
      highWaterMark: 0,
      buffered: 0,
      error: [Circular *2],
      pipeline: null,
      drains: null,
      byteLength: [Function: defaultByteLength],
      map: null,
      afterWrite: [Function: bound afterWrite],
      afterUpdateNextTick: [Function: bound updateWriteNT]
    },
    _predestroy: [Function: predestroy],
    _transformState: TransformState {
      data: null,
      afterTransform: [Function: bound afterTransform],
      afterFinal: [Function: bound afterFinal]
    },
    _flush: [Function: flush],
    _read: [Function (anonymous)],
    [Symbol(shapeMode)]: false,
    [Symbol(kCapture)]: false
  },
  domainThrown: false
}

Please give us a sample of your gulpfile

I created a small repro here: https://gist.github.com/marekdedic/ba636b4fcbf233d65a63b8c1720b057d

Run npm ci && gulp main to see the issue

Terminal output / screenshots

See above the output.

Please provide the following information:

  • OS & version: Ubuntu 22.04
  • node version: v22.0.1
  • npm version: 10.7.0
  • gulp version: 5.0.0

Additional information

At first I thought this was an issue with merge-stream, it's author claims it's not. See grncdr/merge-stream#42.

@phated
Copy link
Member

phated commented May 4, 2024

The merge-stream package is no longer supported, as it isn't a properly behaving stream. You can instead use the ordered-read-stream package that the gulpjs team maintains, which has the same interface/usage as merge-stream.

@phated phated closed this as completed May 4, 2024
@phated
Copy link
Member

phated commented May 4, 2024

For posterity, all streams using {end: false} are unsupported, as that is bad behavior that leads to many footguns and will never be supported by streamx. See mafintosh/streamx#86

@marekdedic
Copy link
Author

Great, thanks, I'll try ordered-read-streams. Could we please maybe have some better error message for this? AFAIK merge-stream has been considered the de facto standard way to do this, so I think I won't be the last person to get confused by this...

Thanks!

timvandermeij added a commit to timvandermeij/pdf.js that referenced this issue May 22, 2024
…reams` dependency

The `merge-stream` dependency is no longer maintained and doesn't work
in combination with Gulp 5 anymore (for more information refer to
gulpjs/gulp#2802 (comment)).

Fortunately the Gulp team maintains a drop-in replacement dependency
called `ordered-read-streams` with the same API as `merge-stream`.
Indeed, running all affected Gulp targets and comparing build artifacts
with `diff -r <old> <new>` confirms that no unexpected changes are made.

Fixes a part of mozilla#17922.
joechung-msft added a commit to joechung-msft/azure-functions-ux that referenced this issue Jul 26, 2024
- Set `encoding` to false to ensure same encoding behavior as Gulp 4.
- Replace `merge-stream` with `ordered-read-streams` because of
gulpjs/gulp#2802 (comment).
@ghnp5
Copy link

ghnp5 commented Jul 27, 2024

Having the same issue here, after upgrading to Gulp 5.

I have a number of gulp.src(...).pipe(...) in a mergeStream().

I was trying to do one by one, and then in one big gulp.src([....]), I was trying file by file, in that array.

It seems that no matter what, if there are 3 items in that src array, it's enough to start triggering this crash.
Seems a bit random, but "consistently", as in as soon as I make it crash, it always crashes.

Definitely something related to mergeStream(), as otherwise, they never fail if outside a merged stream.

I thought I was going to just have to separate all the streams into a big series of many functions, as mergeStream() no longer seems to work well with Gulp 5.

I'll give a try to ordered-read-streams... :)

@ghnp5
Copy link

ghnp5 commented Jul 29, 2024

Yeah, it worked for me, by just changing:

const mergeStream = require('merge-stream');

to:

const mergeStream = require('ordered-read-streams');

(and installing ordered-read-streams, of course)

joechung-msft added a commit to Azure/azure-functions-ux that referenced this issue Jul 29, 2024
- Set `encoding` to false to ensure same encoding behavior as Gulp 4.
- Replace `merge-stream` with `ordered-read-streams` because of
gulpjs/gulp#2802 (comment).
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

3 participants