aws-sdk-js-v3
aws-sdk-js-v3 copied to clipboard
Cannot find name 'ReadableStream'.
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

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

Or if you don't want to download that, you can do the following:
-
npm i @aws-sdk/client-s3 typescript @types/node
- Create
lib/index.ts
with the exact contents listed above - 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/**/*"]
}
- Run
npx tsc
Hopefully this helps. Let me know if I can help any further.
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
Adding "dom"
to the libs section of your tsconfig.json
is not a solution. If you are writing constructs with aws jsii the tsconfig.json
is generated and not editable. This dependency makes it unusable in non-browser environments in my opinion.
This is a duplicate of #2896.
https://github.com/aws/aws-sdk-js-v3/issues/1920#issuecomment-1069472928
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'.
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.
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
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.