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

ReferenceError: ReadableStream is not defined (lib-storage chunker error on Node.js) #2522

Closed
garrett-hopper opened this issue Jun 25, 2021 · 10 comments · Fixed by #3889
Closed
Assignees
Labels
bug This issue is a bug. workaround-available This issue has a work around available.

Comments

@garrett-hopper
Copy link

Sorry for the noise, but can #2312 be reopened? It was closed and later locked with a mentioned of no "recent activity" despite there being a couple comments about it not being resolved.
Was this a bug in the GitHub action not seeing the following comments?

@garrett-hopper garrett-hopper added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jun 25, 2021
@ajredniwja
Copy link
Contributor

Hi @garrett-hopper thanks for brining this is up, It was not a bug with GH actions, the issue was closed intially because of lack of response, which is set to 10 days, then the another GH action locks the thread with no activity for 14 days which was after your comment, we tend to lock the threads since they are not so visible after being locked and we encourage to open new issues if thats the case.

With that being said, I have re-opened the issue but it seems like Alex was not able to reproduce the issue, can you try running his code?

I'll take more questions on other issue, feel free to tag me or anything for any questions.

@garrett-hopper
Copy link
Author

Ah, that makes sense. Thanks!

@garrett-hopper
Copy link
Author

It looks like #2312 is still locked, so I can't comment there.
I'm not sure about @alexforsyth not being able to reproduce the original issue, as the chunker at lib-storage/src/chunker.ts#L22 definitely doesn't handle ReadableStream not being defined on Node.
Nor does it handle objects which match the required spec but don't actually contain any of the checked types in its prototype chain for the instanceof checked.

npm i @aws-sdk/lib-storage tar
node -e "require('@aws-sdk/lib-storage/dist/cjs/chunker').getChunk(require('tar').c({gzip: true}, ['test']))"
/home/garrett/tmp/node_modules/@aws-sdk/lib-storage/dist/cjs/chunker.js:25
    else if (data instanceof ReadableStream) {
                             ^

ReferenceError: ReadableStream is not defined
    at Object.getChunk (/home/garrett/tmp/node_modules/@aws-sdk/lib-storage/dist/cjs/chunker.js:25:30)
    at [eval]:1:50
    at Script.runInThisContext (node:vm:129:12)
    at Object.runInThisContext (node:vm:305:38)
    at node:internal/process/execution:81:19
    at [eval]-wrapper:6:22
    at evalScript (node:internal/process/execution:80:60)
    at node:internal/main/eval_string:27:3

@garrett-hopper
Copy link
Author

I ended up switching from jszip to archiver which provided a proper Node Readable instance.
There's likely others out there which will attempt to use similar libraries which don't provide Node Readable instances, and the ReadableStream browser API not being defined in Node is an annoying red herring to track down.
Ideally it would support some of these less conventional formats, but at the very least, it should fall down to lib-storage/src/chunker.ts#L26 and provide a proper error message.

@ajredniwja ajredniwja reopened this Jun 30, 2021
@ajredniwja
Copy link
Contributor

I'll close the other one and keep this one opened.

@garrett-hopper garrett-hopper changed the title Reopen #2312 (ReferenceError: ReadableStream is not defined) ReferenceError: ReadableStream is not defined (lib-storage chunker error on Node.js) Jun 30, 2021
@mifi
Copy link

mifi commented Oct 10, 2021

I'm also seeing this error with streams created by into-stream. Maybe we can take inspiration from this module? https://github.com/sindresorhus/is-stream/blob/main/index.js

@mifi
Copy link

mifi commented Oct 10, 2021

A workaround is to pipe the stream through a PassThrough stream:

const { PassThrough, pipeline } = require('stream');

const passThrough = new PassThrough();
pipeline(stream, passThrough, () => {});

const upload = new Upload({
  client: new S3({}),
  params: {
    Bucket: '...',
    Key: '...',
    Body: passThrough,
  },
  leavePartsOnError: true,
});

@ByScripts
Copy link

I have the exact same problem.

I'm trying to upgrade SDK from v2 to v3.

v2:

await this._s3.upload(
  {
    Bucket: <a>,
    Key: <b>,
    Body: <c>,
  },
  {
    partSize: <d>,
    queueSize: <e>
  }
)

v3:

const upload = new Upload({
  client: this._s3,
  params: {
    Bucket: <a>,
    Key: <b>,
    Body: <c>,
  },
  partSize: <d>,
  queueSize: <e>,
});

await upload.done();

But I get the error:

ReferenceError: ReadableStream is not defined
    at Object.getChunk (node_modules/@aws-sdk/lib-storage/dist/cjs/chunker.js:25:30)`

Thanks @mifi for the workaround. It seems it works.

@ajredniwja ajredniwja added workaround-available This issue has a work around available. and removed needs-triage This issue or PR still needs to be triaged. labels Jun 20, 2022
@ajredniwja
Copy link
Contributor

Related: #1877 (comment)

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue is a bug. workaround-available This issue has a work around available.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants