larksuite / node-sdk

larksuite open sdk for nodejs
MIT License
131 stars 26 forks source link

调用报错: TypeError: adapter is not a function #51

Closed Elric-pp closed 1 year ago

Elric-pp commented 1 year ago

版本:1.17.1 复现代码:

const client = new lark.Client({
        appId: 'sdfsdf',
        appSecret: 'sdfsdfsdf'
    });
// const tenantAccessToken = await client.tokenManager.getTenantAccessToken()

const result = await client.bitable.appTableRecord.list({
    path: {
        app_token: appToken,
        table_id: tableId
    }
})
[error]: [
  TypeError: adapter is not a function
      at dispatchRequest (/Users/elric/playground/daily-report-v2-worker/node_modules/axios/lib/core/dispatchRequest.js:58:10)
      at Axios.request (/Users/elric/playground/daily-report-v2-worker/node_modules/axios/lib/core/Axios.js:109:15)
      at Axios.httpMethod [as post] (/Users/elric/playground/daily-report-v2-worker/node_modules/axios/lib/core/Axios.js:144:19)
      at Function.wrap (/Users/elric/playground/daily-report-v2-worker/node_modules/axios/lib/helpers/bind.js:9:15)
      at TokenManager.<anonymous> (/Users/elric/playground/daily-report-v2-worker/node_modules/@larksuiteoapi/node-sdk/es/index.js:22372:18)
      at Generator.next (<anonymous>)
      at fulfilled (/Users/elric/playground/daily-report-v2-worker/node_modules/@larksuiteoapi/node-sdk/es/index.js:52:58)
      at processTicksAndRejections (node:internal/process/task_queues:95:5)
]
[mf:err] POST /: TypeError: Cannot destructure property 'tenant_access_token' of '(intermediate value)' as it is undefined.
    at TokenManager.<anonymous> (/Users/elric/playground/daily-report-v2-worker/node_modules/@larksuiteoapi/node-sdk/es/index.js:22371:21)
    at Generator.next (<anonymous>)
    at fulfilled (/Users/elric/playground/daily-report-v2-worker/node_modules/@larksuiteoapi/node-sdk/es/index.js:52:58)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
mazhe-nerd commented 1 year ago

上面的报错看不出什么,如果想要调用多维表格的api完成一些功能,可以参考这篇教程:https://open.feishu.cn/document/home/quick-access-to-base/preparation

wuhan005 commented 4 months ago

我这边是在 Cloudflare Workers 运行,也会报这个错误。

我尝试使用 @haverstack/axios-fetch-adapter 更换掉默认的 axios adapter 可以正常运行:

import fetchAdapter from "@haverstack/axios-fetch-adapter";

client.httpInstance.defaults.adapter = fetchAdapter;

@mazhe-nerd 你们 Lark 是不是对 GitHub Issue 有什么指标要求?不进一步询问用户更详细的错误信息,直接甩一篇不相关的文档然后草草关 issue 就算解决了是吧。😅

7ade8769a8cdf8a68c0db8328a02ac61

mazhe-nerd commented 4 months ago

@wuhan005

不好意思同学😅,这个issue回复一周后没在追问,认为是解决,所以close了,抱歉;

axios默认的adaptor会用XMLHttpRequest(browser)或者http(node),但在 Cloudflare Workers里默认是使用fetch,所以需要自定义一个适配器;这个场景我记一下,之后一起更新到文档里。