Milvus 2 Node.js SDK 错误:“TypeError:类扩展值未定义不是构造函数或 null”

问题描述 投票:0回答:1

注意:在投反对票之前,请阅读整个问题,因为我检查了循环依赖,但没有发现任何循环依赖。

我正在开发我的 Nuxt.js 应用程序。对于数据库,我选择了Milvus。我想做相似度搜索,但在浏览器控制台中遇到错误。

我有以下代码:

app.vue

// Other code

<script setup lang="ts">
import { MilvusClient } from "@zilliz/milvus2-sdk-node";

// I also have other code not related to Milvus here, but I don't think it's relevant

(async () => {
  const milvusClient = new MilvusClient({
    address: "localhost:19530",
    username: "",
    password: "",
  });

  // Similarity search
  const test = await milvusClient.search({
    collection_name: "xxxxx", // My collection name here
    vector: [ // My vector here ],
  });

  // Sort the results by score in descending order
  const sortedResults = test.results.sort((a, b) => b.score - a.score);

  // Display the descriptions with scores
  sortedResults.forEach((result) => {
    console.log(`[${result.score}]: ${result.description}`);
  });
})();
</script>

package.json

{
  "name": "nuxt-app",
  "private": true,
  "type": "module",
  "scripts": {
    "build": "nuxt build",
    "dev": "nuxt dev",
    "generate": "nuxt generate",
    "preview": "nuxt preview",
    "postinstall": "nuxt prepare"
  },
  "devDependencies": {
    "autoprefixer": "^10.4.16",
    "nuxt": "^3.9.3",
    "postcss": "^8.4.33",
    "tailwindcss": "^3.4.1",
    "vue": "^3.4.6",
    "vue-router": "^4.2.5"
  },
  "dependencies": {
    "@nuxt/ui": "^2.10.0",
    "@zilliz/milvus2-sdk-node": "^2.3.5",
    "nuxt-security": "^1.1.0"
  }
}

正如您在上面的

app.vue
中看到的,我使用的是 Milvus 2 Node.js SDK,但我在浏览器控制台中收到以下错误:

TypeError: Class extends value undefined is not a constructor or null
    at node_modules/@grpc/grpc-js/build/src/call.js (@zilliz_milvus2-sdk-node.js?v=bfe1cc22:10658:54)
    at __require (chunk-PIXRU2QS.js?v=bfe1cc22:10:50)
    at node_modules/@grpc/grpc-js/build/src/client.js (@zilliz_milvus2-sdk-node.js?v=bfe1cc22:11182:18)
    at __require (chunk-PIXRU2QS.js?v=bfe1cc22:10:50)
    at node_modules/@grpc/grpc-js/build/src/make-client.js (@zilliz_milvus2-sdk-node.js?v=bfe1cc22:11562:20)
    at __require (chunk-PIXRU2QS.js?v=bfe1cc22:10:50)
    at node_modules/@grpc/grpc-js/build/src/channelz.js (@zilliz_milvus2-sdk-node.js?v=bfe1cc22:11663:25)
    at __require (chunk-PIXRU2QS.js?v=bfe1cc22:10:50)
    at node_modules/@grpc/grpc-js/build/src/subchannel.js (@zilliz_milvus2-sdk-node.js?v=bfe1cc22:12227:22)
    at __require (chunk-PIXRU2QS.js?v=bfe1cc22:10:50)

我大致搜索了这个错误,并在 StackOverflow 上找到了多个答案,说这可能是由循环依赖引起的。我使用

dpdm
来查找潜在的循环依赖。

我运行了以下命令:

dpdm app.vue

但是没有发现循环依赖:

✔ [0/0] Analyze done!
• Dependencies Tree
  - 0) app.vue

• Circular Dependencies
  ✅ Congratulations, no circular dependency was found in your project.

• Warnings

我已经尝试了很长一段时间,按照官方示例,但我无法解决这个错误。

typescript nuxt.js milvus grpc-js
1个回答
0
投票

该库

@grpc/grpc-js
不适用于浏览器,它仅适用于 Node.js。看起来您正在将其作为 Milvus 2 Node.js SDK 的传递依赖项来获取,该 SDK 在其 README 中也声明它需要 Node.js。

© www.soinside.com 2019 - 2024. All rights reserved.