我刚开始使用svelte,并试图制作一个以redis作为db的应用程序。我用我需要的所有db函数创建了一个类型记录文件,并试图将它导入到我的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>发布于 2022-01-04 20:45:52
通常情况下,因为redis -国家预防机制包是为Node.js设计的,所以我会说遵循如何在浏览器中使用npm模块?并使用browserify,以便它能够在浏览器中运行。
在阅读我可以从运行在浏览器中的JavaScript直接连接到Redis服务器吗?之后,我会说您需要一个服务器端设置来连接到您的redis服务器,然后您可以根据需要查询您的服务器端。
发布于 2022-03-04 20:35:46
我也遇到过类似的问题,我从上面读到的理解是,这是因为浏览器客户端试图读取服务器上的db。我还使用了sveltekit,并且通过确保我的代码位于端点中来解决问题,该端点只在服务器上运行,然后调用端点来获取数据。
https://stackoverflow.com/questions/70582006
复制相似问题