TypeError: Class extends value undefined is not a constructor or null (svelte redis)

TypeError: Class extends value undefined is not a constructor or null (svelte redis)

我刚开始使用 svelte 并尝试制作一个以 redis 作为数据库的应用程序。我制作了一个包含我需要的所有数据库函数的打字稿文件,并尝试将其导入到我的 svelte 组件中,但是当我这样做时,出现了以下错误

Class extends value undefined is not a constructor or null
TypeError: Class extends value undefined is not a constructor or null
    at node_modules/@node-redis/client/dist/lib/client/socket.js (http://localhost:3000/node_modules/.vite/chunk-L35TFNQI.js?v=60c87e0f:6515:46)
    at __require (http://localhost:3000/node_modules/.vite/chunk-VP3FZ6LR.js?v=60c87e0f:25:44)
    at node_modules/@node-redis/client/dist/lib/client/index.js (http://localhost:3000/node_modules/.vite/chunk-L35TFNQI.js?v=60c87e0f:9192:20)
    at __require (http://localhost:3000/node_modules/.vite/chunk-VP3FZ6LR.js?v=60c87e0f:25:44)
    at node_modules/@node-redis/client/dist/index.js (http://localhost:3000/node_modules/.vite/redis.js?v=60c87e0f:852:20)
    at __require (http://localhost:3000/node_modules/.vite/chunk-VP3FZ6LR.js?v=60c87e0f:25:44)
    at node_modules/redis/dist/index.js (http://localhost:3000/node_modules/.vite/redis.js?v=60c87e0f:2589:20)
    at __require (http://localhost:3000/node_modules/.vite/chunk-VP3FZ6LR.js?v=60c87e0f:25:44)
    at http://localhost:3000/node_modules/.vite/redis.js?v=60c87e0f:2615:21

这是我的redis文件(即使只有这么多,我也会得到同样的错误)

import redis from 'redis'

export var str = "sample string"

这是我的 svelte 组件的脚本

<script lang="ts">
    import { str } from "../redis_test";
</script>

通常,因为 redis - npm package is designed for Node.js, I would say to follow 并使用 browserify 所以它能够 运行 在浏览器中。

看完Can I connect directly to a Redis server from JavaScript running in a browser?,我会说你需要一个服务器端设置来连接到你的redis服务器,然后你可以根据需要查询你的服务器端。

我遇到过类似的问题,我通过阅读上述内容了解到这是因为浏览器客户端正在尝试读取服务器上的数据库。 我也在使用 sveltekit,我通过确保我的代码在端点中解决了问题,该端点仅在服务器上运行,然后调用端点来获取我的数据。