`Unhandled 'error' event` error in gulp 5
marekdedic opened this issue · comments
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.
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.
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
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!