使用import引入cos-js-sdk-v5提示can't not found name 'Buffer'
notfound945 opened this issue · 2 comments
notfound945 commented
Node 版本
$ node --version
v16.20.0
代码引用
import COS from 'cos-js-sdk-v5'
async getCosUrl (cosImageList: Array<string>) {
const originUrlList: Array<string> = []
const cos = await this.getCosClient()
const credentials = await this.getOSSCredentials()
const { bucket, region, dir } = credentials
for (const imageItem of cosImageList) {
const urlSplitList = this.splitCosImageList(imageItem)
if (urlSplitList && urlSplitList.length > 1) {
const [, cosUrl] = urlSplitList
cos.getObjectUrl({
Bucket: bucket,
Region: region,
Key: dir + cosUrl,
Sign: true
}, (err: COS.CosError, data: COS.GetObjectUrlResult) => {
if (!err) originUrlList.push(data.Url || '')
})
} else {
originUrlList.push(imageItem)
}
}
return originUrlList
}
async getCosClient () {
const credentials = await this.getOSSCredentials()
const { accessKeyID, accessKeySecret, securityToken } = credentials
return new COS({
SecretId: accessKeyID,
SecretKey: accessKeySecret,
SecurityToken: securityToken
})
}
错误日志
ERROR in C:/xxxx/node_modules/cos-js-sdk-v5/index.d.ts(1887,12):
1887:12 Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig.
1885 | /** Request 接口返回值 */
1886 | interface RequestResult extends GeneralResult {
> 1887 | Body?: Buffer,
| ^
1888 | }
1889 |
1890 | // getObjectUrl
Version: typescript 3.9.6
错误截图
livehigh commented
收到反馈 下个版本我们修复一下这里
livehigh commented
fixed in v1.4.18