node-sdk icon indicating copy to clipboard operation
node-sdk copied to clipboard

client 初始化对 protobuf 的 Long 属性赋值产生外部影响

Open xiaohaoxing opened this issue 3 months ago • 1 comments

我在项目中同时使用了 @zilliz/milvus2-sdk-node@larksuiteoapi/node-sdk 2 个依赖库,版本如下

"@zilliz/milvus2-sdk-node": "^2.6.1"
"@larksuiteoapi/node-sdk": "^1.55.0"

现在发现,只要初始化了 lark 的 client,之后再调用 milvus 库的 insert 方法会报错,提示 schema 不匹配。经过 milvus 工程师排查,发现是飞书的 sdk 对 protobufjs 的 Long 类型进行了变更导致的,在业务代码中进行如下修改即可修复:

import Long from 'long'
import * as pb from 'protobufjs'

export const createFeishuBitableService = (appId: string, appSecret: string, baseUrl?: string) => {
  const service = new FeishuBitableService(appId, appSecret, baseUrl)
  // 这两行
  pb.default.util.Long = Long  
  pb.default.configure()
  return service
}

我下载了 sdk 查看,发现代码中确实有操作了 pb 的 Long,将其设置为 undefined。位于 ws-client/proto-buf/pbbp2.js:5

// @ts-nocheck
/*eslint-disable block-scoped-var, id-length, no-control-regex, no-magic-numbers, no-prototype-builtins, no-redeclare, no-shadow, no-var, sort-vars*/
const $protobuf = require("protobufjs/minimal");

$protobuf.util.Long = undefined;
$protobuf.configure();

// Common aliases
const $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util;

想知道这里进行这么赋值的原因是什么?能否更新 SDK 的代码将这里对外部其他依赖库的影响消除?

xiaohaoxing avatar Oct 21 '25 07:10 xiaohaoxing