简体   繁体   English

AWS Javascript SDK v3 - Typescript 由于错误 TS2304 无法编译:找不到名称“ReadableStream”

[英]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.我正在尝试构建使用 AWS Javascript SDK v3 的项目。 Here my tsconfig.json这是我的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):这里是我得到的构建错误的示例(为简洁起见,我删除了一些 output):

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我不明白为什么这会给我这样的问题,即使我已经安装了@types/node模块来支持节点类型

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.原来,为了让 typescript 找到BlobFile等名称,我必须将dom条目添加到我的 tsconfig.json 中的 lib 中。 Here my final tsconfig, which allow me to build the project correctly这是我的最终 tsconfig,它允许我正确构建项目

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

Without including the dom lib in the tsconfig.jsontsconfig.json中不包含dom

// src/@types/dom.ts (or any file included in the tsc compilation)

export {}

declare global {
  type ReadableStream = unknown
  type Blob = unknown
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM