question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot find name 'ReadableStream'.

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:8
  • Comments:10

github_iconTop GitHub Comments

8reactions
hteekcommented, 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.

6reactions
barryhagancommented, Jul 19, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript doesn't compile due to error TS2304: Cannot find ...
Turned out that in order for typescript to find the Blob , File etc. names I had to add the dom entry to...
Read more >
Error: node_modules/@aws-sdk/client-s3/types/S3Client.d.ts ...
Error: node_modules/@aws-sdk/client-s3/types/models/models_0.d.ts (5436,23): Cannot find name 'ReadableStream'.
Read more >
aws/aws-sdk-js-v3 - Gitter
Is it possible to create a readable stream from the S3 client, like it was in v2 of the SDK? I've been digging...
Read more >
Can't deug NodeJs Console App - Visual Studio Feedback
Hi, I can't debug NodeJs console app cause I got output like that: ------ Build started: Project: NodejsConsoleApp1, Configuration: Debug Any CPU ...
Read more >
Creating and using Amazon S3 buckets - AWS Documentation
This sample code can be found here on GitHub . Creating an Amazon S3 bucket. Create a libs directory, and create a Node.js...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found