tencentyun / cos-js-sdk-v5

腾讯云 COS JS SDK(XML API)
https://cloud.tencent.com/product/cos
MIT License
327 stars 566 forks source link

使用import引入cos-js-sdk-v5提示can't not found name 'Buffer' #188

Closed notfound945 closed 1 year ago

notfound945 commented 1 year ago

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

错误截图

image
livehigh commented 1 year ago

收到反馈 下个版本我们修复一下这里

livehigh commented 1 year ago

fixed in v1.4.18