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

Cannot find name 'ReadableStream'. #3063

Closed
fishcharlie opened this issue Nov 24, 2021 · 10 comments · Fixed by #3889
Closed

Cannot find name 'ReadableStream'. #3063

fishcharlie opened this issue Nov 24, 2021 · 10 comments · Fixed by #3889
Assignees
Labels
bug This issue is a bug.

Comments

@fishcharlie
Copy link

Describe the bug

Cannot find name 'ReadableStream'.

Your environment

SDK version number

@aws-sdk/client-s3@3.42.0

Is the issue in the browser/Node.js/ReactNative?

Node.js

Details of the browser/Node.js/ReactNative version

node -v
v16.13.0

Steps to reproduce

import {S3} from "@aws-sdk/client-s3";

(async () => {
	const s3Client = new S3({});
	const data = (await s3Client.getObject({
		"Bucket": "mybucket",
		"Key": "data.txt"
	}));

	console.log(data.Body);
})();

Observed behavior

node_modules/@aws-sdk/client-s3/dist-types/models/models_0.d.ts:6050:23 - error TS2304: Cannot find name 'ReadableStream'.

6050     Body?: Readable | ReadableStream | Blob;
                           ~~~~~~~~~~~~~~

node_modules/@aws-sdk/client-s3/dist-types/models/models_0.d.ts:6697:23 - error TS2304: Cannot find name 'ReadableStream'.

6697     Body?: Readable | ReadableStream | Blob;
                           ~~~~~~~~~~~~~~

node_modules/@aws-sdk/client-s3/dist-types/models/models_0.d.ts:9081:23 - error TS2304: Cannot find name 'ReadableStream'.

9081     Body?: Readable | ReadableStream | Blob;
                           ~~~~~~~~~~~~~~

node_modules/@aws-sdk/client-s3/dist-types/models/models_1.d.ts:837:23 - error TS2304: Cannot find name 'ReadableStream'.

837     Body?: Readable | ReadableStream | Blob;
                          ~~~~~~~~~~~~~~

node_modules/@aws-sdk/client-s3/dist-types/models/models_1.d.ts:1116:23 - error TS2304: Cannot find name 'ReadableStream'.

1116     Body?: Readable | ReadableStream | Blob;
                           ~~~~~~~~~~~~~~

Expected behavior

No TypeScript errors

Screenshots

Screen Shot 2021-11-24 at 11 59 15 AM

Additional context

Also, when running this code, it doesn't print the contents, but instead a large object that looks like a response object. It should print the contents of the file.

@fishcharlie fishcharlie added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 24, 2021
@vudh1 vudh1 self-assigned this Nov 26, 2021
@vudh1
Copy link

vudh1 commented Nov 26, 2021

Hi @fishcharlie, thanks for reaching out. I am not able to reproduce this. Can you show how you set up your credentials and region configuration?

@vudh1 vudh1 added response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. and removed needs-triage This issue or PR still needs to be triaged. labels Nov 26, 2021
@fishcharlie
Copy link
Author

@vudh1 I don't think credentials or region is relevant here. Both are just the default environment variables tho. Nothing passed into the object itself.

Here you can find a link that will expire in 1 week that contains a zip file of a project used to reproduce this: https://fishcharliepersonalbucket.s3-us-west-2.amazonaws.com/tmp.zip?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJ4K33MVV3APAWBLQ/20211127/us-west-2/s3/aws4_request&X-Amz-Date=20211127T001149Z&X-Amz-Expires=604800&X-Amz-SignedHeaders=host&X-Amz-Signature=e3cb3d78504e039905daa374bac615606a6f6e72b1d8defd6f414d717b705863.

With that you should be able to run npm run build and notice errors in the output.

Screen Shot 2021-11-26 at 5 13 41 PM


Or if you don't want to download that, you can do the following:

  1. npm i @aws-sdk/client-s3 typescript @types/node
  2. Create lib/index.ts with the exact contents listed above
  3. Set tsconfig.json to the following:
{
	"compilerOptions": {
		"module": "commonjs",
		"moduleResolution": "node",
		"lib": ["es2015"],
		"target": "es2017",
		"outDir": "dist",
		"sourceMap": true,
		"declaration": true,
		"noImplicitThis": true,
		"strict": false
	},
	"include": ["./lib/**/*"]
}
  1. Run npx tsc

Hopefully this helps. Let me know if I can help any further.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. label Nov 28, 2021
@StevenGBrown
Copy link

I had the same errors and a similar one from @aws-sdk/util-dynamodb: Cannot find name 'File'.

Was able to build after adding "dom" to the libs in tsconfig.json.
https://stackoverflow.com/a/66275649

@hteek
Copy link

hteek commented Dec 9, 2021

Adding "dom" to the libs section of your tsconfig.json is not a solution. If you are writing constructs with aws jsii the tsconfig.jsonis generated and not editable. This dependency makes it unusable in non-browser environments in my opinion.

@jfirebaugh
Copy link

This is a duplicate of #2896.

@vudh1 vudh1 removed their assignment Feb 22, 2022
@shuzootani
Copy link

#1920 (comment)

@nwalters512
Copy link
Contributor

nwalters512 commented Jul 18, 2022

I started encountering this after the changes from #3779 were pulled into my project. I can work around this by adding either "lib": ["DOM"] or "skipLibCheck": true to my tsconfig.json, but neither of those is particularly appealing.

../../node_modules/@aws-sdk/types/dist-types/serde.d.ts(58,33): error TS2304: Cannot find name 'ReadableStream'.

@barryhagan
Copy link

The other option is to use declaration merging to stub out the missing interface that aws-sdk assumes is available. Add this where you are exporting code that uses the SDK:

declare global {
     interface ReadableStream {}
 }

That should allow you to compile without hauling in the entire DOM lib.

@ElihuJ
Copy link

ElihuJ commented Jul 28, 2022

The other option is to use declaration merging to stub out the missing interface that aws-sdk assumes is available. Add this where you are exporting code that uses the SDK:

declare global {
     interface ReadableStream {}
 }

That should allow you to compile without hauling in the entire DOM lib.

Good enough to keep it running

@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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants