aws-sdk-js-v3 icon indicating copy to clipboard operation
aws-sdk-js-v3 copied to clipboard

Cannot find name 'ReadableStream'.

Open fishcharlie opened this issue 3 years ago • 9 comments

Describe the bug

Cannot find name 'ReadableStream'.

Your environment

SDK version number

@aws-sdk/[email protected]

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 avatar Nov 24 '21 18:11 fishcharlie

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 avatar Nov 26 '21 20:11 vudh1

@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.

fishcharlie avatar Nov 27 '21 00:11 fishcharlie

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

StevenGBrown avatar Dec 02 '21 08:12 StevenGBrown

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.

hteek avatar Dec 09 '21 10:12 hteek

This is a duplicate of #2896.

jfirebaugh avatar Dec 16 '21 17:12 jfirebaugh

https://github.com/aws/aws-sdk-js-v3/issues/1920#issuecomment-1069472928

shuzootani avatar Mar 31 '22 01:03 shuzootani

I started encountering this after the changes from https://github.com/aws/aws-sdk-js-v3/pull/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'.

nwalters512 avatar Jul 18 '22 21:07 nwalters512

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.

barryhagan avatar Jul 19 '22 03:07 barryhagan

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

ElihuJ avatar Jul 28 '22 01:07 ElihuJ

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[bot] avatar Sep 14 '22 00:09 github-actions[bot]