What / Why
When you attempt to extract a tarball through streams sometimes it will be closed with an error: [ERR_STREAM_PREMATURE_CLOSE]: Premature close, although the files are successfully extracted. No Errors Codes are shown in the process.
It seems to happen only on newer versions of Node > v18
Looking at the spec it seems now that streams that emit a close event before a end event trigger this error, so worth taking a look on that.
When
Where
How
Current Behavior
- It throws an
ERR_STREAM_PREMATURE_CLOSE Error when trying to extract
Steps to Reproduce
$ nvm install 18.7.0
$ npm install tar got
$ mkdir output
import stream from 'node:stream';
import { promisify } from 'util';
import tar from 'tar';
import got from 'got';
const pipeline = promisify(stream.pipeline);
pipeline(
got.stream('https://codeload.github.com/npm/node-tar/tar.gz/main'),
tar.extract({ cwd: './output' }, ['node-tar-main/lib'])
)
Expected Behavior
- It should extract the content of the archive without any issues
References
- Related to Next.js Issue #39321
What / Why
When you attempt to extract a tarball through streams sometimes it will be closed with an error:
[ERR_STREAM_PREMATURE_CLOSE]: Premature close, although the files are successfully extracted. No Errors Codes are shown in the process.It seems to happen only on newer versions of Node > v18
Looking at the spec it seems now that streams that emit a
closeevent before aendevent trigger this error, so worth taking a look on that.When
Where
How
Current Behavior
ERR_STREAM_PREMATURE_CLOSEError when trying to extractSteps to Reproduce
Expected Behavior
References