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

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

我正在尝试构建使用 AWS Javascript SDK v3 的项目。这是我的 tsconfig.json

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

这是我得到的构建错误示例(为简洁起见,我删除了一些输出):

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

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

原来为了让 typescript 找到 BlobFile 等名称,我必须将 dom 条目添加到我的 tsconfig.json 中的库中.这是我的最终 tsconfig,它允许我正确构建项目

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

tsconfig.json

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

export {}

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