Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Javascript SDK v3 - Typescript doesn't compile due to error TS2304: Cannot find name 'ReadableStream'

I'm trying to build my project that uses the AWS Javascript SDK v3. Here my tsconfig.json

{
  "compilerOptions": {
    "target":"ES2020",
    "module": "commonjs",
    "lib": ["es2020"],
    "outDir": "dist",
    "resolveJsonModule": true,
  },
  "exclude": [
    "coverage",
    "node_modules",
    "dist",
    "tests"
  ]
}

And here an example of the build error I get (I've strip out some of the output for brevity sake):

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

node_modules/@aws-sdk/client-s3/types/models/models_1.d.ts:727:40 - error TS2304: Cannot find name 'Blob'.

node_modules/@aws-sdk/util-dynamodb/types/models.d.ts:19:86 - error TS2304: Cannot find name 'File'.

I don't understand why this is giving me such an issue, even if I have installed the @types/node module to support node typing

like image 922
Kerruba Avatar asked Feb 19 '21 10:02

Kerruba


1 Answers

Turned out that in order for typescript to find the Blob, File etc. names I had to add the dom entry to the lib in my tsconfig.json. Here my final tsconfig, which allow me to build the project correctly

{
  "compilerOptions": {
    "target":"ES2020",
    "module": "commonjs",
    "lib": ["es2020", "dom"],
    "outDir": "dist",
    "resolveJsonModule": true,
  },
  "exclude": [
    "coverage",
    "node_modules",
    "dist",
    "tests"
  ]
}
like image 57
Kerruba Avatar answered Oct 10 '22 12:10

Kerruba