AWSJavascriptSDKv3-由于错误TS2304,Typescript无法编译:找不到名称“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支持节点输入的模块
回答
原来,为了让打字稿找到Blob,File等名字,我不得不添加的dom条目的lib在我tsconfig.json。这是我的最终 tsconfig,它允许我正确构建项目
{
"compilerOptions": {
"target":"ES2020",
"module": "commonjs",
"lib": ["es2020", "dom"],
"outDir": "dist",
"resolveJsonModule": true,
},
"exclude": [
"coverage",
"node_modules",
"dist",
"tests"
]
}
THE END
二维码